加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Delphi程序带参数运行

发布时间:2020-12-15 09:54:21 所属栏目:大数据 来源:网络整理
导读:程序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(ParamCo

程序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.

程序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;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读