Search code examples
delphidelphi-2010gesture

How can I see who triggered an Gesture Standard action in Delphi?


I had searched and find How can I see who triggered an action in Delphi?

The solution for that question is using TAction.ActionComponent.

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

Now In the execute event, it is good to know which component has initialized the gesture so that I can decide what to do. (e.g. there are two panel and I need to know which panel to scroll).

However, The TAction.ActionComponent is nil in this case.

I tried OnGesture but defined Gesture do not trigger that event and the sender is always the form itself.

So How can I know which component had triggered that Gesture action?

Thank you.


Solution

  • With more testing I think that one of the solution might be skip using action and use Form.OnGesture and then use the EventInfo.Location to find out which component the gesture started at. Then we can use the EventInfo.GestureID to decide what thing to do.

    procedure TForm5.FormGesture(Sender: TObject; const EventInfo: TGestureEventInfo; var Handled: Boolean);
    var
      C : TControl;
    begin
      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;
      end;
    end;
    

    Any better answer preferably lay inside the action execution is welcomed.