How can I find out who caused the Gesture action in Delphi?

I searched and found How do I know who called an action in Delphi?

The solution to this issue is using the TAction.ActionComponent method.

I have a form with a TGestureManager setting a standard gesture (say left and right) with actions.

Now in the execute event it's good to know which component initiated the gesture so that I can decide what to do. (for example there are two panels and I need to know which panel to scroll).

However, in this case, the TAction.ActionComponent parameter is zero.

I tried OnGesture, but the specific Gesture didn't fire that event and the sender is always the form itself.

So how can I find out which component has caused the Gesture action?



source to share

1 answer

With a lot of testing, I think one solution could be skipped using an action and using Form.OnGesture and then using EventInfo.Location to see which component the gesture was started with. We can then use EventInfo.GestureID to decide what to do.

procedure TForm5.FormGesture(Sender: TObject; const EventInfo: TGestureEventInfo; var Handled: Boolean);
  C : TControl;
  C := FindVCLWindow(ClientToScreen(EventInfo.Location));
  if Assigned(C) and (EventInfo.GestureID < 0) then
    edt1.Text := C.Name
  case EventInfo.GestureID of
    1 : DoThis;
    2 : DoThat;


Any better answer is appreciated, preferably within the execution of the action.



All Articles