发现Delphi7中的ParamCount有点问题它一直就是一。
不信可以试试!!
http://www.delphibbs.com/delphibbs/dispq.asp?lid=2473543
我改了一个:
GetParamList输入一个TStrings(如TStringList),分解的结果在其中,返回参数的个数。
--------------------------------------------------------------------------------
function GetParamList(list: TStrings):integer;
var
P: PChar;
S: string;
function GetParamStr(P: PChar; var Param: string): PChar;
var
i, Len: Integer;
Start, S, Q: PChar;
begin
while True do
begin
while (P[0] <> #0) and (P[0] <= ' ') do
P := CharNext(P);
if (P[0] = '"') and (P[1] = '"') then Inc(P, 2) else Break;
end;
Len := 0;
Start := P;
while P[0] > ' ' do
begin
if P[0] = '"' then
begin
P := CharNext(P);
while (P[0] <> #0) and (P[0] <> '"') do
begin
Q := CharNext(P);
Inc(Len, Q - P);
P := Q;
end;
if P[0] <> #0 then
P := CharNext(P);
end
else
begin
Q := CharNext(P);
Inc(Len, Q - P);
P := Q;
end;
end;
SetLength(Param, Len);
P := Start;
S := Pointer(Param);
i := 0;
while P[0] > ' ' do
begin
if P[0] = '"' then
begin
P := CharNext(P);
while (P[0] <> #0) and (P[0] <> '"') do
begin
Q := CharNext(P);
while P < Q do
begin
S := P^;
Inc(P);
Inc(i);
end;
end;
if P[0] <> #0 then P := CharNext(P);
end
else
begin
Q := CharNext(P);
while P < Q do
begin
S := P^;
Inc(P);
Inc(i);
end;
end;
end;
Result := P;
end;
begin
list.Clear;
Result := 0;
P := CmdLine;
while True do
begin
P := GetParamStr(P, S);
if S = '' then Break;
list.Add(S);
Inc(Result);
end;
end;
// 例示程序,将参数表放到Memo1里,将参数个数显示到Caption
procedure TForm1.FormCreate(Sender: TObject);
begin
Caption := IntToStr(GetParamList(Memo1.Lines));
end;