Atozed Forums
component property check ? - Printable Version

+- Atozed Forums (https://www.atozed.com/forums)
+-- Forum: Atozed Software Products (https://www.atozed.com/forums/forum-1.html)
+--- Forum: IntraWeb (https://www.atozed.com/forums/forum-3.html)
+---- Forum: English (https://www.atozed.com/forums/forum-16.html)
+----- Forum: IntraWeb General Discussion (https://www.atozed.com/forums/forum-4.html)
+----- Thread: component property check ? (/thread-1250.html)



component property check ? - SorenJensen - 09-18-2019

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

Regards
Soren


RE: component property check ? - kudzu - 09-18-2019

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;
begin
Result := _Context.GetType(aObj.ClassType).GetProperty(aName) as TRttiInstanceProperty;
end;


RE: component property check ? - SorenJensen - 09-18-2019

Hi Kudzu,

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

Regards
Soren


RE: component property check ? - Alexandre Machado - 09-24-2019

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
TIWCustomControl(Self.Components[i]).Font.Assign(YourFontHere);

or

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


RE: component property check ? - kudzu - 09-24-2019

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