现在的位置: 首页 > 综合 > 正文

Delphi2007获取对象的published方法

2014年02月17日 ⁄ 综合 ⁄ 共 804字 ⁄ 字号 评论关闭

 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;

抱歉!评论已关闭.