830
社区成员
发帖
与我相关
我的任务
分享
传参实例:D:\Temp\csdn.exe -FD:\Program Files\hi.exe
调用示例:
var Params: string;
if FindCmdLineSwitch('F', Params) > 0 then ShowMessage(Params)
实现:
function FindCmdLineSwitch(const Switch: string; var Params: string; IgnoreCase: Boolean): Integer;
var
I: Integer;
S: string;
begin
Result := 0;
for I := 1 to ParamCount do
begin
S := ParamStr(I);
if (S[1] in SwitchChars) then
if IgnoreCase then
begin
if (AnsiCompareText(Copy(S, 2, Length(Switch)), Switch) = 0) then
begin
Params := Copy(S, Length(Switch) + 2{Switch的位置+1, 起始位置再+1, 下同}, Maxint);
Result := I;
Exit;
end;
end
else begin
if (AnsiCompareStr(Copy(S, Length(Switch) + 2, Maxint), Switch) = 0) then
begin
Params := Copy(S, Length(Switch), Maxint);
Result := I;
Exit;
end;
end;
end;
end;