Question : Popup menu onclick doesn't fire event

I have a popup menu which dynamically creates captions based on the value in a grid (asg2), and it works like I want it to... except.... the OnClick event doesn't fire.

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
procedure TForm1.asg2MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
  var ts :string;
      mi1,mi2 : TMenuItem;
begin
  if Button = mbRight then
    begin
      asg2.Row := ASG2.MouseCoord(X,Y).Y;
      AdvPopupMenu1.Items.Clear;

      mi1 := TMenuItem.Create(AdvPopupMenu1);
      mi1.Caption := 'Ping '+asg2.cells[0,asg2.row];
      mi1.OnClick := Ping2Click;

      mi2 := TMenuItem.Create(AdvPopupMenu1);
      mi2.Caption := 'Check '+asg2.cells[0,asg2.row];
      mi2.OnClick := Check1Click;
      AdvPopupMenu1.Items.Add([mi1,mi2]);

      if  ((ASG2.MouseCoord(X,Y).X=0)) then
          AdvPopupMenu1.PopupAtCursor;
      mi1.Destroy;
      mi2.Destroy;
    end;
end;


Neither Ping2Click nor Check1Click will fire when the respective menu item is selected.

Any ideas?

Answer : Popup menu onclick doesn't fire event

Just a quick look through your code, why are you creating these meniutems and then destroying them in the same procedure?
The way you've done it otherwise seems to be correct -- you assign the name of the eventhandler to the event, as in
  mi2.OnClick := Check1Click;  
Then when the user clicks on mi2, Check1Click gets called
You can then use the Sender parameter to see which button called it.

However, after you said mi2.OnClick := Check1Click; in your source-code, you immediately destroy it, i.e. mi2.destroy;
Random Solutions  
 
programming4us programming4us