[Lazarus] command line options

Joao Morais post at joaomorais.com.br
Thu May 29 14:17:23 CEST 2008


Mattias Gaertner wrote:
> On Wed, 28 May 2008 16:55:39 -0700
> el stamatakos <el_stamatakos at hotmail.com> wrote:
> 
>> Hi,
>>  I would like my application to understand command line options. For
>> example if I type in gedit my app creates some error message if I
>> enter gedit -test it opens the app. Any ideas? Thanks
> 
>   ErrMsg:=Application.CheckOptions('f:h','file: help');
>   if ErrMsg<>'' then begin
>     writeln('Wrong options: ',ErrMsg);
>     ShowHelp;
>     exit;
>   end;
>   if Application.HasOption('h','help') then
>     ShowHelp;
>     exit;
>   end;
>   Filename:=Application.GetOptionValue('f','filename');
> 
> See
> http://www.freepascal.org/docs-html/fcl/custapp/tcustomapplication.checkoptions.html

You can also use ParamCount and ParamStr:

begin
   if ParamCount = 0 then
     // error - no param
   if ParamStr(1) <> '-test' then
     // error - invalid param

Joao Morais



More information about the Lazarus mailing list