启动程序的同时传参给接收程序(XE8+WIN764)

启动程序的同时传参给接收程序(XE8+WIN764)

相关资料:

http://blog.csdn.net/yanjiaye520/article/details/7590252

注意事项:

1.ParamStr(0)是实例自己。

2.传的参数是以空格分看的。

3.“‘2 Hello World”,ParamStr(1) = '2' ;

发送窗体:

 unit Unit1;

 interface

 uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, ShellAPI, Vcl.StdCtrls; type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public { Public declarations }
end; var
Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject);
begin
ShellExecute(Handle, 'open','project2.exe','2 Hello World',nil,SW_SHOWNORMAL);
end; end.

接收窗体:

 unit Unit1;

 interface

 uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls; type
TForm1 = class(TForm)
ListBox1: TListBox;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject);
begin
//ParamStr(0)是实例自己,所以参数从1开始;而且传的参数是以空格分看的,“‘2 Hello World”,ParamStr(1) = '2' 了;
ListBox1.Items.Add(ParamStr());
end; end.

PS:如果使用CreateProcess建进程,怎么发参数呢?

     if not IsBuildInFit then
begin //不代参数
bActiveState := CreateProcess(PChar(nil), PChar(GetExePath + sHardWareName), @lpsaProcess,
@lpsaThread, false, CREATE_SHARED_WOW_VDM, PChar(nil), PChar(nil),
lpsiStartInfo, oProcInfo);
end
else
begin //代参数
bActiveState := CreateProcess(PChar(nil), PChar(GetExePath + sHardWareName + ' True'), @lpsaProcess,
@lpsaThread, false, CREATE_SHARED_WOW_VDM, PChar(nil), PChar(nil),
lpsiStartInfo, oProcInfo);
end;
上一篇:dos系统


下一篇:Oracle获取一周前,一个月前,一年前, 本周,本月,当年的日期