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.

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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM