Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2014-01

how about a "HasProperty()" property?

4 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Alejandro Gonzalo

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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20140105/d9d9acc9/attachment.html>

Reply by email

Howard Page-Clark
to Alejandro Gonzalo
Alejandro Gonzalo wrote 6 lines
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;

Reply by email

Michael Van Canneyt
to Howard Page-Clark

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.

Howard Page-Clark wrote 34 lines
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 http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Mailing Lists
Alejandro Gonzalo wrote 6 lines
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

Reply by email