Is there a simple statement that can give a result similar to paramstr() in Delphi?
+5
A:
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
2009-12-09 17:26:47