是否有一个简单的语句可以给出类似于 Delphi 中的 paramstr() 的结果?
问问题
344 次
1 回答
5
Delphi Prism (.Net) 不包含ParamStr函数,但可以使用GetCommandLineArgs方法轻松实现,这是一个示例:
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;
于 2009-12-09T17:26:47.580 回答