2

Is there a simple statement that can give a result similar to paramstr() in Delphi?

Arioch 'The
  • 15,799
  • 35
  • 62
Bill Seven
  • 768
  • 9
  • 27

1 Answers1

5

Delphi Prism (.Net) does not include the ParamStr function, but can be easily implemented using the GetCommandLineArgs method, here is an example :

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;

Also you can see the ShineOn project that includes an implementation of the function ParamStr.

RRUZ
  • 134,889
  • 20
  • 356
  • 483