您现在的位置:首页 >> VCL >> VCL >> 内容

Delphi中判断控件是否有某个属性

时间:2011/9/3 16:24:34 点击:

  核心提示:functionFindProperty(AClass:TObject;sPropertyName:String):Boolean; var PropList:PPropList; ClassType...
function FindProperty(AClass: TObject; sPropertyName: String): Boolean;
var
  PropList: PPropList;
  ClassTypeInfo: PTypeInfo;
  ClassTypeData: PTypeData;
  i: integer;
begin
  Result := False;
  ClassTypeInfo := aClass.ClassType.ClassInfo;
  ClassTypeData := GetTypeData(ClassTypeInfo);
  if ClassTypeData.PropCount <> 0 then
  begin
    GetMem(PropList, SizeOf(PPropInfo) * ClassTypeData.PropCount);
    try
      GetPropInfos(AClass.ClassInfo, PropList);
      for i := 0 to ClassTypeData.PropCount - 1 do
        if (PropList[i]^.PropType^.Kind <> tkMethod)
          and (UpperCase(PropList[i]^.Name) = UpperCase(sPropertyName)) then
        begin
          Result := True;
          Break;
        end;
    finally
      FreeMem(PropList, SizeOf(PPropInfo) * ClassTypeData.PropCount);
    end;
  end;
end;

作者:网络 来源:转载
共有评论 0相关评论
发表我的评论
  • 大名:
  • 内容:
本类推荐
  • 没有
本类固顶
  • 没有
  • 盒子文章(www.2ccc.com) © 2024 版权所有 All Rights Reserved.
  • 沪ICP备05001939号