procedure GetObjectPublishedMethods(const AObj: TObject;
var AList: TStringList);
var
VMT: Pointer;
pMethodInfo: Pointer;
nCount: Integer;
begin
AList.Clear;
VMT := PPointer(AObj)^;
repeat
pMethodInfo := PPointer(Integer(VMT) + vmtMethodTable)^;
if pMethodInfo <> nil then
begin
nCount := PWord(pMethodInfo)^;
Inc(Integer(pMethodInfo), 2);
while nCount > 0 do
begin
AList.Add(PMethodInfoHeader(pMethodInfo)^.Name);
Inc(Integer(pMethodInfo), PMethodInfoHeader(pMethodInfo)^.Len);
Dec(nCount);
end;
end;
VMT := PPointer(Integer(VMT) + vmtParent)^;
if VMT <> nil then
VMT := PPointer(VMT)^;
until VMT = nil;
end;
将方法published方法绑定到控件事件:
var
oMethod: TMethod;
begin
oMethod.Code := oFrm.MethodAddress('AA');
oMethod.Data := oFrm;
TButton(oFrm.FindComponent('Button1')).OnClick := TNotifyEvent(oMethod);
end;