使用ParamStr,ParamStr(0)表示接收到的第一个参数,依次类推。ParamCount返回参数个数。procedure TForm1.FormCreate(Sender: TObject);
var
  i: Integer;
  for i := 0 to ParamCount - 1 do
  begin
    if LowerCase(ParamStr(i)) = 'beep' then //如果发现有'beep'参数则发声
      Beep(10000,1000)
    else if (LowerCase(ParamStr(i)) = 'exit' then //如果有'exit'参数则退出
      Application.Terminate;
  end;
end;调用时执行project.exe 'beep'

解决方案 »

  1.   

    paramcount 函数 返回在命令行上传递给程序的参数数量 
    paramstr 函数 返回指定的命令行参数 呼叫 ParamStr(0), 传回执行档的档名(含路径)
    呼叫 ParamStr(n), 传回第n个参数的内容
    procedure TForm1.FormCreate(Sender: TObject);
    var
    sFileName: string;
    begin
    if ParamCount > 0 then begin (* 有执行参数传入 *)
    sFileName := ParamStr(1); (* 取得参数内容 *)
    if FileExists(sFileName) then
    Memo1.Lines.LoadFromFile(sFileName)
    else
    Application.MessageBox('找不到指定的档案', '讯息', 48);
    end;
    end;