开发环境Delphi Xe11.3
调用的程序
procedure TForm2.Button1Click(Sender: TObject); begin //某个参数包含空格时(用""),如下面这行 ;这里传递过去是3个参数 ShellExecute(handle,'open',pchar( 'C:\Users\PC\Desktop\新建文件夹\新建文件夹\Win32\Debug\Project2.exe' ), PChar('"AA BB" "SSS"Exit Exit'),PChar(''),sw_shownormal); //这里传递过去是4个参数 //ShellExecute(handle,'open',pchar( 'C:\Users\PC\Desktop\新建文件夹\新建文件夹\Win32\Debug\Project2.exe' ), PChar('AA BB SSS Exit'),PChar(''),sw_shownormal); end;
被调用的程序
procedure TForm2.Button1Click(Sender: TObject); var i: Integer; s:string; begin ShowMessage(IntToStr(ParamCount)); s:=ParamStr(0) ; ShowMessage(s);//这个是程序绝对路径 for i := 1 to ParamCount do begin s:=ParamStr(i) ; ShowMessage(s); if LowerCase(ParamStr(i)) = 'aa bb' then ShowMessage('22') else if LowerCase(ParamStr(i)) = 'exit' then Application.Terminate; end; end;