有关RTTI,请问如何从一个控件中通过一个事件名称得到该事件的类型信息PTypeInfo(有一定难度)?
在此虚心请教各位达人。
比如给定TButton,及名称'OnClick',如何得到OnClick对应的事件的PTypeInfo?
函数定义如下:
function GetEventTypeInfo(ComponentClass:TPersistentClass; EventName: string):PTypeInfo;
begin
//??? 这里如何实现?
end;
因为只知道一个类名和一个事件名,而不知道具体的事件类型,所以不能直接使用TypeInfo(TNotifyEvent)这样的方式直接取得事件的类型信息,而要通过类和事件名来取得,事件是published的。
在此虚心请教各位达人。
比如给定TButton,及名称'OnClick',如何得到OnClick对应的事件的PTypeInfo?
函数定义如下:
function GetEventTypeInfo(ComponentClass:TPersistentClass; EventName: string):PTypeInfo;
begin
//??? 这里如何实现?
end;
因为只知道一个类名和一个事件名,而不知道具体的事件类型,所以不能直接使用TypeInfo(TNotifyEvent)这样的方式直接取得事件的类型信息,而要通过类和事件名来取得,事件是published的。
解决方案 »
- 关于delphi的窗口调用问题
- 两个窗体相互use(引用)对整个程序会不会有什么不良影响,会不会影响程序性能?
- 如何将插入oracle数据库的number字段的数值保留小数点后两位?
- 关于线程的问题?
- 请问 select 字段1,........字段25 from tablename 出错了!!
- 关于窗体如何释放的问题?
- 小弟是DELPHI的一只菜鸟,各位能帮我解决吗?
- 用存储过程如何实现商品出库的功能(Delphi 7 & SQL 2005)
- 急寻好用的扫描控件!
- delphi中第三方控件dxDBGrid中数据表每条信息想用横线分开,用那个属性,请高手赐教,谢谢?
- 如何监视串口的数据???
- Parameters属性问题
function GetEventTypeInfo(ComponentClass:TPersistentClass; EventName: string):PTypeInfo;
var
p:PPropInfo;
begin
p:= GetPropInfo(ComponentClass,EventName,tkMethods);
if p <> nil then
result := p^.PropType^;
end;
http://blogs.codegear.com/abauer/2007/06/14/36043
var
p:PPropInfo;
begin
p:= GetPropInfo(ComponentClass,EventName,tkMethods);
if p <> nil then
result := p^.PropType^;
end;-------------------------------------------------
嗯,我就是这样用的。
取得PTypeInfo有什么用呢=>>
当然有用,在delphi7中的DesignEditors.pas中有一个函数:
procedure RegisterPropertyEditor(PropertyType: PTypeInfo; ComponentClass: TClass;
const PropertyName: string; EditorClass: TPropertyEditorClass);
其中第一个参数PropertyType需要传入的就是一个PTypeInfo类型的。简单的解释下用途,
我要用GetEventTypeInfo动态的取得一个类(不是类的实例)的published的事件的PTypeInfo,如果该类存在这个事件,就传到RegisterPropertyEditor动态注册一个该事件的PropertyEditor。
比如GetEventTypeInfo(TButton,'OnClickXXX'),GetEventTypeInfo(TButton,'OnClick')等等,其中两个参数都是动态的,未知的,如果返回的不是Nil,那就说明这个类有这个事件,我就把它给注册了~~