copy 过来的。 这方法只有在类里面的方法或函数才可实现,如果是单元公共过程或函数就不知了。 像SysUtils里面的过程和函数就无法实现了,不知各位还有没高招? type {$M+} TMyObj = class published function CommandOne: Integer; function CommandTwo: Integer; function CommandThree: Integer; function CommandFour: Integer; end; {$M-}function DoCommand1(const Command: string): Integer; var CommandProc: function: Integer of object; begin TMethod(CommandProc).Code := TMyObj.MethodAddress(Command); if Assigned(TMethod(CommandProc).Code) then Result := CommandProc; end;-- WBR, LVT.PS: A second method by V.Titov :uses TypInfo;type TCommand = (CommandOne, CommandTwo, CommandThree, CommandFour);function DoCommand2(const Command: string): Integer; begin Result := 0; case TCommand(GetEnumValue(TypeInfo(TCommand), Command)) of CommandOne: ..; CommandTwo: ..; CommandThree: ..; CommandFour: ..; end; end;
这方法只有在类里面的方法或函数才可实现,如果是单元公共过程或函数就不知了。
像SysUtils里面的过程和函数就无法实现了,不知各位还有没高招?
type
{$M+}
TMyObj = class
published
function CommandOne: Integer;
function CommandTwo: Integer;
function CommandThree: Integer;
function CommandFour: Integer;
end;
{$M-}function DoCommand1(const Command: string): Integer;
var
CommandProc: function: Integer of object;
begin
TMethod(CommandProc).Code := TMyObj.MethodAddress(Command);
if Assigned(TMethod(CommandProc).Code) then Result := CommandProc;
end;--
WBR, LVT.PS: A second method by V.Titov :uses
TypInfo;type
TCommand = (CommandOne, CommandTwo, CommandThree, CommandFour);function DoCommand2(const Command: string): Integer;
begin
Result := 0;
case TCommand(GetEnumValue(TypeInfo(TCommand), Command)) of
CommandOne: ..;
CommandTwo: ..;
CommandThree: ..;
CommandFour: ..;
end;
end;
s(54)怎么解释?
但是前提是IntToStr这样的函数有限个。