[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;
   if not Assigned(aComponent) or (aProperty='') then
   Result:=GetPropInfo(aComponent, aProperty)<>nil;

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

More information about the Lazarus mailing list