Thursday, 28 February 2013

Iterate through controls on a form

Here is how to iterate through all the controls on a form, this is very useful for setting a property value of more than one control, for example the enabled property.

procedure IterateControls(AControl: TControl);
        iControl: Integer;
        if AControl = nil then
        if AControl is TWinControl then
            for iControl := 0 to TWinControl(AControl).ControlCount - 1 do

        // Do Control stuff here
        AControl.Enabled := false;

Where you want to set the control property value it is possible to check for the class something like this.

if (AControl is TButton) then
   (AControl as TButton).Enabled := false;

And, of course the boolean value can be passed as a parameter to the procedure.

FireMonkey Retina Detection

Just read that with FireMonkey it will detect if the device is a retina display and if the property BitmapHighRes is set it will use this image over the standard Bitmap property image. This sounds like it should make things easier than xCode, because you do not have to name them with the @2x included in the filename. I just hope this supports PNG files.