看来这里没有人想到用TStringList实现——
type
ProcPointer=procedure;
var
ProList:TStringList;
procedure A;
begin
MessageDlg('This is A!',mtInformation,[mbOK],0);
end;
procedure B;
begin
MessageDlg('This is B!',mtInformation,[mbOK],0);
end;
procedure DoProc(Name:String);
var
n:Integer;
begin
n:=ProList.IndexOf(Name);
if n>=0 then
ProcPointer(ProList.Objects[n]);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
DoProc('A');
DoProc('B');
end;
initialization //编译器不是万能的,要实现你的要求,必须手工绑定
ProList:=TStringList.Create;
ProList.Sorted:=true;
ProList.AddObject('A',TObject(@A));
ProList.AddObject('B',TObject(@B));
finalization
ProList.Free;
end.
——怎么样?不算复杂吧。