Delphi Prism中的paramstr等价物是什么

时间:2009-12-09 17:23:58

标签: delphi delphi-prism oxygene

是否有一个简单的语句可以在Delphi中给出类似于paramstr()的结果?

1 个答案:

答案 0 :(得分:5)

Delphi Prism(.Net)不包含ParamStr函数,但可以使用GetCommandLineArgs方法轻松实现,here就是一个例子:

class method TMyClass.ParamStr(Index: Integer): String;
var
  MyAssembly: System.Reflection.Assembly;
  Params    : array of string;
begin
  if Index = 0 then
  begin
    MyAssembly:= System.Reflection.Assembly.GetEntryAssembly;
    if Assigned(MyAssembly) then
      Result := MyAssembly.Location
    else
      Result := System.Diagnostics.Process.GetCurrentProcess.MainModule.FileName;
  end
  else
  begin
    Params := System.Environment.GetCommandLineArgs;
    if Index > Length(Params) - 1 then
      Result := ''
    else
      Result := Params[Index];
  end;
end;

此外,您还可以看到ShineOn项目,其中包含函数ParamStr的实现。