码农的笔记

Delphi虽好,但已不流行; 博客真好,可以做笔记

博客园 首页 新随笔 联系 订阅 管理

开发环境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;

 

posted on 2023-08-07 15:48  码农的笔记  阅读(271)  评论(0编辑  收藏  举报