Re: [Lazarus] how about a HasProperty() property?
On Sunday 05/01/2014 at 11:51 pm, Alejandro Gonzalo wrote: Is there someway else to do that? Yes, simply use RTTI (Runtime Type Information). See the typinfo unit. I've also created an unit for the tiOPF project - it is full of extended RTTI helper methods that could make the work much easier. See the tiRTTI.pas unit. [http://sourceforge.net/p/tiopf/code/ci/tiopf2/tree/Core/tiRTTI.pas] Those helper/utility methods could easily be adapted to exclude any tiOPF dependencies. Regards, Graeme -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
[Lazarus] how about a HasProperty() property?
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. Perhaps being able to test for the Palate that the component is on would work, is there a way to do that? Thanks. A. G. -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] how about a HasProperty() property?
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@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] how about a HasProperty() property?
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@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus