Parsing Command Line Parameters with Delphi
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:


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;
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