Recent

Author Topic: Calling an Action from onDragDrop Event  (Read 1470 times)

jufau

  • New Member
  • *
  • Posts: 42
Calling an Action from onDragDrop Event
« on: July 08, 2015, 07:54:29 pm »
Hi all,
I have created an ActionList initially with 2 Actions:
* One to Clean up the content of my editButton Compoment. This action will be linked to the Event OnButtonClick of my editButton component.

procedure TformQSA.limpaEditsExecute(Sender: TObject);
begin
    TEditButton (Sender).Clear;
end;


* Second One is to accept the content dragged from a listbox, which will drop a string on my editButton. This action should be linked to the OnDragDrop event of my editButton component. But for some reason I don't see my action on the "OnDragDrop" event option.

procedure TformQSA.pegaNomeCampoExecute(Sender: TObject);
begin
    TEditButton(Sender).Text:=ListBox1.GetSelectedText;
end;


I am wondering whether the ActionLists are called only from the onClick of components. Any clue?
thanks
J

howardpc

  • Hero Member
  • *****
  • Posts: 3672
Re: Calling an Action from onDragDrop Event
« Reply #1 on: July 08, 2015, 10:14:10 pm »
You need form procedures something like what follows (the exact names depend on how you have named your TEditButton), and of course the ListBox1.DragMode property set to dmAutomatic.

Code: [Select]
procedure TFormQSA.EditButton1ButtonClick(Sender: TObject);
begin
  limpaEditsExecute(Sender);
end;

procedure TFormQSA.limpaEditsExecute(Sender: TObject);
begin
  if (Sender is TEditButton) then
    TEditButton(Sender).Clear;
end;

procedure TFormQSA.pegaNomeCampoExecute(Sender: TObject);
begin
  if (Sender is TEditButton) then
    TEditButton(Sender).Text:=ListBox1.GetSelectedText;
end;

procedure TFormQSA.EditButton1DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
  if (Sender is TEditButton) and (Source is TListBox) then
    pegaNomeCampoExecute(Sender);
end;

However, you do know that you can program the EditButton.DragDrop and EditButton.OnButtonClick events directly, without needing to use actions at all? Actions are only useful in this case if the same action is to be performed by the user via other means as well (called from a menu, executed by a timer etc.)
« Last Edit: July 08, 2015, 10:22:09 pm by howardpc »

 

TinyPortal © 2005-2018