Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Handling of focus in FMX is not native - how to do it right?


This question is not answered. Helpful answers available: 1. Correct answers available: 1.


Permlink Replies: 1 - Last Post: Mar 9, 2017 7:53 AM Last Post By: Eli M
Hans Jakobsen

Posts: 103
Registered: 9/10/01
Handling of focus in FMX is not native - how to do it right?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 6, 2017 3:15 AM
In FMX, a focus rect/glow is shown when a control is clicked.
However, the native behavior in both OS X and Windows, is to only show the focus indication if you use TAB to reach the control. If you click it with the mouse it does not show any focus indicators (except for edit boxes, which shows they are ready to receive keyboard input).

I suppose there is no general way to change the behavior so it works correctly for all FMX components at once? (TControl does have a DisableFocusEffect property, but something needs to turn it on and off)
Therefore I am mainly interested in solving it for my own custom FMX components. There best solution I can think of is:
In Mousedown: DisableFocusEffect := true
In OnExit: DisableFocusEffect := false.

That solution works, but is there a better solution?

Any ideas or thoughts about how to do it?
Eli M

Posts: 1,346
Registered: 11/9/13
Re: Handling of focus in FMX is not native - how to do it right?
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 9, 2017 7:53 AM   in response to: Hans Jakobsen in response to: Hans Jakobsen
Your solution sounds decent enough.

Maybe you could apply it to all controls at once automatically with Duck Duck Delphi.

https://github.com/deadserious/duckduckdelphi

Or maybe this will be useful:

// Find a child control that is under the given coordinates (form coordinates)
// The control must be able to accept mouse events, e.g. HitTest=True
function TImageCacheLayout.FindControlAtPoint(aParent: TControl; aPos: TPointF): TControl;
var
  I: Integer;
  Control, ChildControl: TControl;
  S: String;
begin
  Result := nil;
 
  // Check all the child controls and find the one at the coordinates
  for I := aParent.Controls.Count - 1 downto 0 do
  begin
    Control := aParent.Controls[I];
    S := Control.ClassName;
    if Control.PointInObject(aPos.X, aPos.Y) and (Control <> fCacheImage) then
    begin
      ChildControl := FindControlAtPoint(Control, aPos);
      if Assigned(ChildControl) and ChildControl.HitTest then
        Exit(ChildControl)
      else
        if Control.HitTest then
          Exit(Control);
    end;
  end;
end;
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02