记得以前用C/C++的时候,可以写这样的程序:
void main (Arg[], ??)  
不好意思,“?”表示我忘了!!!
这样的C程序在生成以后,可以用"xx.exe /aa.txt"的命令在command里执行(当然,先要在系统里注册了以后才可以)。问题是,现在我在Delphi里要实现这样的程序,那要怎么做啊!
我连是否要建工程都不确定,因为我觉得工程一建,不就把.exe给定死了吗???不知道谁做过的,请指点一二吧!

解决方案 »

  1.   

    如下内置的方法,可以直接获得EXE的入口参数。如果想写不定参函数,建议用结构指针,因为接口不符合API标准,不方便移植。UnitSystemParamCount functionReturns the number of parameters passed on the command line.ParamStr functionReturns a specified parameter from the command-line.
      

  2.   

    void main( int argc, char *argv[ ], char *envp[ ] ) // 这是基于console的int WINAPI WinMain(
      HINSTANCE hInstance,  // handle to current instance
      HINSTANCE hPrevInstance,  // handle to previous instance
      LPSTR lpCmdLine,      // pointer to command line
      int nCmdShow          // show state of window
    );
    // 这是基于SDK的。。DELPHI也可以写基于console的程序的呀 看中午给你一个例子
      

  3.   

    To beyondtkl(大龙驹<梦.考古广告人生>):强烈期待中。。
      

  4.   

    可以直接用ParamCount,ParamStr获取exe参数procedure TForm1.FormCreate(Sender: TObject);var
      i: Integer;
      for i := 1 to ParamCount do
      begin
        if LowerCase(ParamStr(i)) = 'beep' then
          Beep
        elseif LowerCase(ParamStr(i)) = 'exit' then
          Application.Terminate;
      end;
    end;
      

  5.   

    // 你在新建向导中 选择 Console Application.
    program Project2;{$APPTYPE CONSOLE}uses
      SysUtils, Classes;var
      I:      Integer;
      MyFile: TFileStream;
      tt: TextFile;
    begin
      { TODO -oUser -cConsole Main : Insert code here }
      WriteLn('Here begin ');
      for I := 0 to ParamCount do
      begin
        WriteLn(ParamStr(i));
      end;
      // 假设输入的控制台命令为 Project2 test.txt aaa
      // 表示将aaa 写到test.txt中
      // 1. 创建 test.txt
      try
        MyFile := TFileStream.Create(ParamStr(1), fmCreate or fmOpenReadWrite);
      except
        MyFile.Free;
        MyFile := nil;
      end;
      if MyFile <> nil then
      begin
        MyFile.Free;
      end;
      // 2. 将后面的字符串写道文件中
      AssignFile(tt, ParamStr(1));
      ReWrite(tt);
      Write(tt, ParamStr(2));
      CloseFile(tt);
    end.其余的类似操作
    注意 ParamStr(0)表示本身exe所在目录,后面就依次是输入的命令了。
      

  6.   

    可以通过ParamStr来获得的
    如果只带一个参数,可以这样写
     System.ParamStr(1) ;
    然后再用你的程序处理这个参数
    如果你是打开文件的话,可以写一个带这个参数的过程
    OpenPrj(fn:string);
    在启动时判断参数在不在,如果有就执行
    OpenPrj(System.ParamStr(1));
      

  7.   

    谢谢大家了!虽然分数不多!!!再次强烈感谢beyondtkl ,anbeel ,zhangguanshi (排名不分先后)