When i programatically pop up the popup-menu using button1 click, and when poped up the meun then click the item1 of popup menu item to call event handler.
After then click the button2.
I expect the message is displayed 'Process Popup'.
But result is 'Item1 Clicked!'.
What's happening and how can i get the result what i expect.
//Popup Menu Item1 Click event handler
procedure MyForm.Item1Click(Sender: TObject);
begin
FMsg := 'Item1 Clicked!';
end;
procedure MyForm.ProcessPopup(APoint: TPoint);
begin
PopupMenu1.Popup(APoint.X, APoint.Y);
FMsg := 'Process Popup';
end;
procedure MyForm.Button1Click(Sender: TObject);
begin
ProcessPopup(Mouse.x, Mouse.Y);
end;
procedure MyForm.Button2Click(Sender: TObject);
begin
ShowMessage(FMsg);
end;
If you would set some breakpoints and use F8 to step through your code you would see what is wrong.
Anywhay the reason why the message displayed is 'Item1 Clicked!' is becouse that is set to FMsg variable at the time.
The flow of your code is like this:
NOTE: Calling "PopMenu1.Popup(APoint.X, APoint.Y)" does not stop your code to wait on which Popup Item will you click. I think you mixed up the popup menu functionality with modal forms (Dialogs) where the code actually do waits for modal result returned from such form.