Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 2 of 2 total
Thread Notification on focus change of controls
Tue, Oct 6 2015 2:32 AMPermanent Link

Christian Kaufmann

I want to create a subclass of TBasicPanel where I have a method, that will be called when the
focus moves from one control on the panel to the next.

Do I have to catch OnEnter/OnExit of each control on my panel or is there a simpler way to do it in
the panel class directly?

cu Christian
Tue, Oct 6 2015 11:20 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Christian,

<< I want to create a subclass of TBasicPanel where I have a method, that will be called when the focus moves from one control on the panel to the next. >>

Now is where you start to realize that creating a custom control has its advantages. Wink

Doing things like this are trivial when the outer container control has complete control over the sub-controls (and creates them).  With such a scenario, it's simply a matter of creating descendant classes for the child controls that forward all/some of their events on to their parent/owner control.  The grid cells, for example, use this technique for mouse/touch events:

function TGridCell.DispatchEvent(ID: Integer; AElement: TElement): Boolean;
begin
  if ((ID >= cdMouseDown) and (ID <= cdMouseWheel) or
      (ID >= cdTouchStart) and (ID <= cdTouchCancel)) then
     Result:=ForwardEvent(ParentGrid.Element,ID,AElement)
  else
     Result:=inherited DispatchEvent(ID,AElement);
end;

The ForwardEvent method is a protected method of the base TInterfaceController class (ancestor of TControl that provides basic element-to-control functionality).

However, if you don't want to create descendant controls for the sub-controls, then you'll need to do the OnEnter/OnExit tracking instead.

Tim Young
Elevate Software
www.elevatesoft.com
Image