运行期获取控件全部事件

From  http://delphi.about.com/od/adptips2005/qt/listhandlers.htm

~~~~~~~~~~~~~~~~~~~~~~~~~
USES TYPINFO, .... !!!!

procedure TForm1.FormCreate(Sender: TObject) ;

var
Count, Loop: Integer;
List: PPropList;
method : TMethod;
begin
Count := GetPropList(TypeInfo(TForm1), tkMethods, nil) ;// 也可以写为 Self.ClassType
GetMem(List, Count * SizeOf(PPropInfo)) ;
try
GetPropList(TypeInfo(TForm1), tkMethods, List) ;
for Loop := 0 to Pred(Count) do
begin
Listbox1.Items.Add(List[Loop]^.Name) ;
method := GetMethodProp(Form1, List[Loop]^.Name) ;
if Assigned(method.Code) and Assigned(method.Data) then
begin
ListBox2.Items.Add(List[Loop]^.Name) ;
end;
end;
finally
FreeMem(List, Count * SizeOf(PPropInfo))
end;

end;


http://www.hur.cn/special/delphiProgram/06482.htm

list all properties, events of a component?

列出控件所有属性和事件?

uses

  TypInfo;

procedure ListComponentProperties(Component: TComponent; Strings: TStrings);

var

  Count, Size, I: Integer;

  List: PPropList;

  PropInfo: PPropInfo;

  PropOrEvent, PropValue: string;

begin

  Count := GetPropList(Component.ClassInfo, tkAny, nil);

  Size  := Count * SizeOf(Pointer);

  GetMem(List, Size);

  try

    Count := GetPropList(Component.ClassInfo, tkAny, List);

    for I := 0 to Count - 1 do

    begin

      PropInfo := List^[I];

      if PropInfo^.PropType^.Kind in tkMethods then

        PropOrEvent := 'Event'

      else

        PropOrEvent := 'Property';

      PropValue := VarToStr(GetPropValue(Component, PropInfo^.Name));

      Strings.Add(Format('[%s] %s: %s = %s', [PropOrEvent, PropInfo^.Name,

        PropInfo^.PropType^.Name, PropValue]));

    end;

  finally

    FreeMem(List);

  end;

end;

// Example: List all Properties/Events from Button1 in a TListBox

procedure TForm1.Button1Click(Sender: TObject);

begin

  ListComponentProperties(Button1, ListBox1.Items);

end;


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值