Delphi程序带参数运行


本文整理自网络,侵删。

 
程序1
program E1;
uses
Forms,Dialogs,SysUtils,
EndM1 in 'EndM1.pas' {Form2};
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TForm2, Form2);
if ParamCount<>3 then
begin
ShowMessage('缺少参数:'+Inttostr(ParamCount));
Application.Terminate;
Exit;
end;
//在运行时去读是否有带参数值
if ParamStr(1)<>'-x' then
begin
ShowMessage('缺少参数:'+ParamStr(1));
Application.Terminate;
Exit;
end;
Application.Run;
end.
Paramcount-->用于返回命令行参数的个数
Paramstr数组-->用于返回指定的命令行参数
showmessage('命令行参数个数为:'+inttostr(paramcount));
showmessage('第1个命令行参数为:'+paramstr(1));
showmessage('应用程序名称为:'+paramstr(0));

程序2
uses ShellAPI;
{$R *.dfm}
//function ShellExecute(hWnd: HWND; Operation, FileName, Parameters,Directory: PChar; ShowCmd: Integer): HINST; stdcall;
procedure TForm1.btn1Click(Sender: TObject);
var
sFileName,sParam,sFilePath: string;
begin
sFileName:=ExtractFilePath(Application.ExeName)+'E1.exe';
sFilePath:=ExtractFilePath(Application.ExeName);
sParam:='-x -y -z';
ShellExecute(0, 'Open', PChar(sFileName), PChar(sParam), PChar(sFilePath), SW_SHOW);
end;

来源:http://www.delphixe.net/2018/08/04/delphi%E7%A8%8B%E5%BA%8F%E5%B8%A6%E5%8F%82%E6%95%B0%E8%BF%90%E8%A1%8C/

相关阅读 >>

Delphi2007-Delphi2010 程序不出现在任务栏的方法

Delphi winapi: getparent - 判断两个窗口是不是父子关系

Delphi线程池

Delphi memo 控件光标定位

Delphi listview高速添加数据

Delphi 提取html网页源文件纯文本函数可做采集

Delphi 如何将整数值转换为罗马数字表示形式

Delphi生成的webservice appdebug的程序,编译时出错

Delphi 判断表字段是否存在

Delphi base64单元encddecd的修改

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...