Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
component property check ?
Hi All,

Having the component loop working for a form, I want to use it to change some properties for individual components, based on user prefs.

How can I check for the presence of a certain property, like font, which is not something all components have ?

Using "if (selv.Components[i] as TIWCustomControl) is TIWLabel ..." requires IWCompLabel to be present in the Uses clause. 

If I want to check if the component has a font property, how can I do that without refering to the component type ?

And will it be possible to set, say font.size, for all IWLabels, IWButtons and IWEdits on the form, without having to include all the types in the uses clause ?

I'm trying to create a general procedure I can call in each forms create event, to avoid having to put all the code in every form.

Advises and examples are gracefully accepted

IW has a history running back over 20 years so I cant say why Font was not added in a base or given an interface, but it wasnt. As you've seen Font is introduced on various end classes.

Thus the way to do what you want is RTTI and dynamically check for the Font properties.

Delphi since 2006 or so has Extended RTTI which is a bit easier to work with. It works from C++ builder as well.

17 uses RTTI extensively.

A small snippet:

function T17Reflector.GetProperty(aObj: TPersistent; const aName: string): TRttiInstanceProperty;
Result := _Context.GetType(aObj.ClassType).GetProperty(aName) as TRttiInstanceProperty;
Hi Kudzu,

Thanks for the reply. I try it out and see where it gets me.

I don't know where the information came from.... Property Font is a public property for TIWCustomControl class.

All you need to do is:

if (Self.Components[i] is TIWCustomControl) then


if (Self.Components[i] is TIWCustomControl) then
TIWCustomControl(Self.Components[i]).Font.FontFamily := 'Verdana, Helvetica, Sans-Serif';
Alexandre is correct.

I searched and was surprised that it wasn't in a base class but now I realize that the search results had led me to source that wasn't IW core source and someone had implemented Font in those controls rather than use the inherited one.

I really wish they would improve the Delphi search Sad

Forum Jump:

Users browsing this thread: 1 Guest(s)