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 -------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20080528/e91d26dc/attachment.html
Mailing lists / lazarus / 2008-05
command line options
5 messages · 5 people · –
- Eel stamatakos 1
- JJoao Morais 1
- MMarco van de Voort 1
- MMattias Gaertner 1
- MMattias Gärtner 1
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
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
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 paramJoao 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.
An embedded and charset-unspecified text was scrubbed... Name: not available
Url: http://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20080529/aee4ef2a/attachment.pl
