2
Y at-il une instruction simple qui peut donner un résultat similaire à paramstr() dans Delphi?Quel est l'équivalent de paramstr dans Delphi Prism
Y at-il une instruction simple qui peut donner un résultat similaire à paramstr() dans Delphi?Quel est l'équivalent de paramstr dans Delphi Prism
Delphi Prism (.Net) ne comprend pas la fonction ParamStr, mais peut être facilement mis en œuvre en utilisant la méthode GetCommandLineArgs, here est un exemple:
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;
vous pouvez également voir le projet ShineOn qui comprend une mise en œuvre de la fonction ParamStr.