firemonkey - Delphi FMX set focus to a particular control so the cursor appears -
i created test new fmx project. added tabcontrol it. used context menu add 3 tabsheets. 3rd tabsheet, added tedit. added onchangeevent handler tabcontrol. coded follows:
procedure tform1.tabcontrol1change(sender: tobject); begin if tabcontrol1.activetab = tabitem3 begin self.activecontrol := edit1; self.focused := edit1; edit1.setfocus; end; end;
as can see, tried various combinations based on previous vcl experience. input/cursor focus not change edit1 code. of course, @ runtime on win32, if click on edit1, focus rectangle (i'm using style) shows cursor. (as expected) on android. vk comes when shift focus myself.
is there way programmatically user can start typing? (without having shift focus tedit themselves).
the firemonkey framework prohibits change of focus in events.
in order change focus, send delayed message form.
this done anonymous thread:
procedure tform1.tabcontrol1change(sender: tobject); begin if tabcontrol1.activetab = tabitem3 begin tthread.createanonymousthread( procedure begin tthread.synchronize( nil, procedure begin edit1.setfocus; end ); end ).start; end; end;
to make more general, use dedicated procedure:
procedure delayedsetfocus(control : tcontrol); begin tthread.createanonymousthread( procedure begin tthread.synchronize( nil, procedure begin control.setfocus; end ); end ).start; end;
Comments
Post a Comment