Link to home
Start Free TrialLog in
Avatar of AivsCoder
AivsCoder

asked on

How do I make a different components on my form share the same popupmenu and distinguish between the different senders

Hello,

I have three components on the form which will have the same popupmenu items. To me,  It makes sense for me to use one popupmenu for all three components  . How do I find out which component it is currently doing businesss with? (sender?? or owner??) im not sure.

Thanks,

Ben
ASKER CERTIFIED SOLUTION
Avatar of Geert G
Geert G
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AivsCoder
AivsCoder

ASKER

thanks
Hey I was wondering if you knew the answer to this one:
Its a similar question

I have a popupmenu on a VirtualStringTree and I click on the VirtualStringTree item and then right click on the popup menu and click on the menu item.

The sender is then the menu item and not the VirtualStringTree.
In this example, I need the VirtualStringTree to be the sender and not the PopupMenu.

so I did this:

vtSender : string;
begin
vtSender := TVirtualStringTree(sender).Name; inside the OnClickEvent for VirtualStringTree
end;

but it in order for me to pass vtSender to the procedure that requires it, I have to make it a global variable.

Is there a way to get the sender before the current sender??
Ben

the popupmenu initiates the onclick event and is the sender of that event

If you have multiple virtualstringtree (or components of the same type)
then you would use the onEnter event on all components of the same type
and store the last focused in a private variable

type
  TFormX = class(TForm)
  private
    fLastFocusedVTS: TVirtualStringTree;
  end;

procedure TFormX.VirtualStringTreeYEnter(Sender: TObject);
begin
  fLastFocusedVTS := TVirtualStringTree(Sender);  
end;

attach this onEnter event to all stringtree's
and in the menuitem event you can check which was the last focused stringtree in fLastFocusedVTS
this is the easiest way