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

Michael Van Canneyt michael at freepascal.org
Mon Jan 6 08:59:06 CET 2014


Unit typinfo contains:

Function IsPublishedProp(Instance: TObject; const PropName: string): Boolean;
Function IsPublishedProp(AClass: TClass; const PropName: string): Boolean;

That should do what you want.

Michael.

On Mon, 6 Jan 2014, Howard Page-Clark wrote:

> 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;
>
>
> --
> _______________________________________________
> Lazarus mailing list
> Lazarus at lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>




More information about the Lazarus mailing list