码迷,mamicode.com
首页 > Windows程序 > 详细

Delphi程序带参数运行

时间:2018-11-03 14:01:15      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:util   begin   log   fun   std   direct   hwnd   file   ati   

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

 

Delphi程序带参数运行

标签:util   begin   log   fun   std   direct   hwnd   file   ati   

原文地址:https://www.cnblogs.com/westsoft/p/9900216.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!