发信人: soaringbird(假行僧*飞翔鸟)
整理人: teleme(2001-05-20 13:17:14), 站内信件
|
判断控件有哪一属性
利用 TObject 的 ClassInfo 取得 run-time type information(RTTI) table 的指针, 然後利用 TypInfo 单元中的 GetPropInfo 函数判断传回值是否为 nil 来决定是否有这个属性.
--------------------------------------------------------------------------------
C++ Builder
请参照Delphi的例子
--------------------------------------------------------------------------------
Delphi
implementation
uses TypInfo;
{$R *.DFM}
function HasProperty(AObject: TObject; const APropName: string): boolean;
begin
Result := GetPropInfo(AObject.ClassInfo, APropName) <> nil;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
{ GetPropInfo(TypeInfo: PTypeInfo; const PropName: string): PPropInfo;}
if HasProperty(Button1, 'Caption') then
ShowMessage('Yes')
else
ShowMessage('No');
end;
---- 抵制日货,从我做起!
坚决不给日本鬼子做事!
求职条件之一:日资、中日合资、中日合作企业免谈。
|
|