procedure TForm1.FormCreate(Sender: TObject);var
  i: Integer;
  for i := 0 to ParamCount ?1 do
  begin
    if LowerCase(ParamStr(i)) = 'beep' then
      Beep(10000,1000)
    else if (LowerCase(ParamStr(i)) = 'exit' then
      Application.Terminate;
  end;
end;命令行: *.exe beep

解决方案 »

  1.   

    zswang(伴水)(* 嘻 *) 
    这位大哥是什么意思,能不能说的清楚些
      

  2.   

    ParamStr returns the parameter from the command line that corresponds to Index, or an empty string if Index is greater than ParamCount. For example, an Index value of 2 returns the second command-line parameter.ParamStr(0) returns the path and file name of the executing program (for example, C:\TEST\MYPROG.EXE).
      

  3.   

    这段程序我看过,有问题,调试不出来,也不知道怎么样去调试是不是这样?
    c:\project1.exe /beep对吗?
      

  4.   

    delphi 打开菜单run --> paramters 在local 页paramter 中输入 beep
      

  5.   

    就是上面那段程序,使用了 yijnew(倚星) 提供的方法,调试了之后没有反应呀,是怎么一回事。
      

  6.   

    在标准Pascal语法中program文件(就是工程文件)是可以带参数的。
    program MyApp(InnFile, OutFile,{Other parameters});
    可惜Object Pascal编译器忽略这些参数。
    所以你只能用ParamCount(), ParamStr()这两个函数来处理程序的命令行参数了。
      

  7.   

    请问该如何写呢?能不能给我一个例程(最好能自己写的,调试通过,不要把delphi的帮助给我)
      

  8.   

    例子程序改成:
    procedure TForm1.FormCreate(Sender: TObject);
    var
      i: Integer;
    begin
      for i := 0 to ParamCount do
      begin
        if LowerCase(ParamStr(i)) = 'beep' then
          showmessage('ok')
        else if (LowerCase(ParamStr(i)) = 'exit') then
          Application.Terminate;
      end;
    end;delphi 打开菜单run --> paramters 在local 页paramter 中输入 beep调试通过
      

  9.   

    命令行: project1.exe beep
      

  10.   

    返回程序执行参数   有关 Delphi 传入应用程式的命令列参数, 请参考以下的说明:
    用ParamCount函数取得命令参数的个数:
    呼叫 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;
      

  11.   

    procedure TForm1.FormCreate(Sender: TObject);var
      i: Integer;
    begin
      for i := 0 to ParamCount do
      begin
         if LowerCase(ParamStr(i)) = 'beep' then
         windows.Beep(10000,1000)
        else if LowerCase(ParamStr(i)) = 'exit' then
          Application.Terminate;
      end;
    end;
      

  12.   

    刚才我看了一下ParamCount函数的源代码,发现了Bug:
    function ParamCount: Integer;
    {$IFDEF MSWINDOWS}
    var
      P: PChar;
      S: string;
    begin
      Result := 0;     // 错在这一句,再怎么说也应该从1开始嘛,因为
                       // ParamStr(0)返回的是命令部分,这肯定是存在的。
                       // 所以只要将这句改为 Result := 1; 就应该没问题了。 
      P := GetParamStr(GetCommandLine, S);
      while True do
      begin
        P := GetParamStr(P, S);
        if S = '' then Break;
        Inc(Result);
      end;
    {$ENDIF}
    {$IFDEF LINUX}
    begin
      if ArgCount > 1 then
        Result := ArgCount - 1
      else Result := 0;
    {$ENDIF}
    end;
      

  13.   

    你可以把这个函数复制到你的unit里面,然后把错的那句改掉,应该就可以用了。这个函数在System单元中。
      

  14.   

    或许,这也不能算一个Bug,因为如果这样用:
    for i := 0 to ParamCount do...
    那么结果也是正确的。奇怪的编码方式!
    混乱的数组基址。:(