3

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.

Community
  • 1
  • 1
Justmade
  • 1,496
  • 11
  • 16

1 Answers1

0

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.

Justmade
  • 1,496
  • 11
  • 16
  • Truth is that the `TActionManager.OnExecute` event parameter `Action.ActionComponent = nil` however the actions itself are being executed. Have no clue why do you want to use the actions (`TAction`) and case a `GestureID` or whatever. You can simply assign to the gesture of a certain component `TAction` to be executed and it happens. – TLama Mar 07 '12 at 12:30
  • If you read the original question, you will know I want to know the gesture start from which control, which I cannot find when executed by assigned action. – Justmade Mar 07 '12 at 12:38