1. Home
  2. Computing & Technology
  3. Delphi Programming
Zarko Gajic
Zarko's Delphi Programming Blog

By Zarko Gajic, Delphi Programming Guide

Parsing Command Line Parameters with Delphi

Monday February 22, 2010

in Delphi TIPS :: Delphi's ParamStr and ParamCount functions are designed to help operate the parameters (command-line arguments) passed to the application. Due to the way ParamStr function is implemented in Delphi, parameters passed using double quotes ("") will not be parsed correctly (quotes will be removed). The "CmdLineHelper" unit provides 3 custom Delphi functions to overcome the problem of the RTL's ParamStr implementation.

Read the full article to learn how to Parse Command Line Parameters with Delphi ("double quote parameters fix").

Related:

Comments
February 22, 2010 at 9:24 am
(1) Fabio vitale says:

I currently use a funclion like the following one to parse tagged parameter lists.
For example i can call my executable with this command line:

myprogram.exe user=”john doe” password=”secret pass”

function GetParamVal(const TaggedParm: string;
IgnoreCase: boolean = true): string;
var
Cmd: string;
i, Len: integer;
Comp1, Comp2: string;
begin
Cmd := ”;
Comp1 := TaggedParm + ‘=’;
if IgnoreCase then
Comp1 := UpperCase(Comp1);

Len := length(Comp1);

for i := 1 to ParamCount do
begin
Comp2 := copy(ParamStr(i), 1, Len);
if IgnoreCase then
Comp2 := UpperCase(Comp2);
if (Comp1 = Comp2) then
begin
Cmd := trim(copy(ParamStr(i), Len + 1, length(ParamStr(i))));
break;
end;
end;

if IgnoreCase then
Result := UpperCase(Cmd)
else
Result := Cmd;
end;

February 24, 2010 at 3:00 am
(2) Ron says:

I modified this original code for parsing

function TForm1.SimpleParse(MainString, BeginString, EndString: string): string;

var

PosBeginString: integer;

PosEndString: integer;

begin

PosBeginString := Pos(BeginString, MainString) + Length(BeginString);

PosEndString := Pos(EndString, MainString);

Result := Copy(MainString, PosBeginString, PosEndString – PosBeginString);

end;

my favorite delphi components http://www.components4developers.com

Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>

Explore Delphi Programming
About.com Special Features

You don't have to break the bank on a new computer. Find out how to save on your next PC. More

This simple questionnaire will show you which Web design software tool is right for you. More

  1. Home
  2. Computing & Technology
  3. Delphi Programming

©2010 About.com, a part of The New York Times Company.

All rights reserved.