[Lazarus] how about a "HasProperty()" property?

Howard Page-Clark hdpc at talktalk.net
Mon Jan 6 08:46:22 CET 2014


On 05/01/2014 23:50, Alejandro Gonzalo wrote:
> For example, if you want to loop though components and set the
> dbNavigator's DataSource property to that of the component if it has a
> DataSource property (and of course is not a dbNavigator itself).  It
> seems you can't do that by using the component's hierarchy.  Is there
> someway else to do that?  Components do seem to have HasHelp and
> HasParent properties already.

Something like this:

uses typinfo;

function ComponentHasProperty(aComponent: TComponent; aProperty: 
string): boolean;
begin
   if not Assigned(aComponent) or (aProperty='') then
     Exit(False);
   Result:=GetPropInfo(aComponent, aProperty)<>nil;
end;

function ClassHasProperty(aClass: TClass; aProperty: string): boolean;
begin
   if (aProperty='') then
     Exit(False);
   Result:=GetPropInfo(aClass, aProperty)<>nil;
end;





More information about the Lazarus mailing list