FiremonkeyGeneral Topics

Firemonkey forgot to add a changed event when changing tabcontrol tabs/indexes

Leave it to Firemonkey for making an experienced Delphi developer’s day frustrating.

When you change tabs on a tabcontrol, chances are you want to place focus on a component on the current tab.  Well, there is no “changed event” to accomplish this.  Luckily I found this code on a Russian website *.

    procedure DelayedSetFocus(control: TControl);
    begin
        TThread.CreateAnonymousThread(
        procedure
        begin
            TThread.Synchronize(nil,
                procedure
                begin
                    control.SetFocus;
                end);
        end).Start;
    end;

What this code does is delays setting focus on the control until the tabcontrol tab changes to the new tab. Simple and it works.

* http://qaru.site/questions/5727723/delphi-fmx-set-focus-to-a-particular-control-so-the-cursor-appears

Leave a Reply

Your email address will not be published. Required fields are marked *