delphi中的命令行及参数怎么用?
这几个函数GetCommandLine,ParamStr,ParamCount都是怎么用?
谁能解释一下或者给个例子学习一下?

解决方案 »

  1.   

    GetCommandLine取整个命令行
    ParamStr(n)取第n个参数
    ParamCount取参数的总个数
      

  2.   

    这是例子.
    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;
      

  3.   

    GetCommandLine其实是个API,Delphi封装了,
    ParamStr(n)第n个参数,从0开始,ParamStr(0)为自己程序的完整路径,相当于Application.ExeName;
    ParamCount参数个数,不包括ParamStr(0).
      

  4.   

    同C中void main(arg[])   是一回事,GetCommandLine  就是取全部的參數Paramsstr  就是索引號去參數。Paramcount  這個就很明顯了,參數數量。
      

  5.   

    abc.exe p1 p2
    ParamStr(1)='p1'
    ParamStr(2)='p2'