Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2008-05

command line options

5 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Mattias Gaertner
to el stamatakos
Show quoted text 5 lines
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

Mattias

Reply by email

Joao Morais
to Mattias Gaertner
Mattias Gaertner wrote 22 lines
On Wed, 28 May 2008 16:55:39 -0700 el stamatakos 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

Reply by email

Marco van de Voort
to Joao Morais
Joao Morais wrote 8 lines
You can also use ParamCount and ParamStr: begin if ParamCount = 0 then // error - no param if ParamStr(1) '-test' then // error - invalid param

Or unit getopts directly. TCustomApplication apparantly wraps this if I see the argument names.

Reply by email