创建popupmenu procedure TfrmParameter.CreatePopupMenu();
var
i: Integer;
begin
for i := 1 to 8 do
begin
if mmiTemp[i] = nil then
begin
mmiTemp[i] := TMenuItem.Create(nil);
mmiTemp[i].Caption := '发送到机台 ' + IntToStr(i);
mmiTemp[i].Tag := i;
//mmiTemp[i].
mmiTemp[i].OnClick := OcbPopupHandler;
pmUpdateIpAndMac.Items.Add(mmiTemp[i]);
end;
end;
end;
事件:procedure TfrmParameter.OcbPopupHandler(Sender: TObject);
var
Position: integer;
begin
Position := (sender as TMenuitem).Tag;
UpdateIpAndMacByPopupMenu(Position);
end;
procedure TfrmParameter.UpdateIpAndMacByPopupMenu(Position: integer);
begin
showmessage('Test');
end;
限制popupmenu弹出范围
procedure TfrmParameter.StrGrdIportListMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
col, row: integer;
begin
StrGrdIportList.MouseToCell(x, y, col, row);
Label1.Caption := Format('x:%d,y:%d row:%d,col: %d mouse X%d', [x, y, row, col, Mouse.CursorPos.X]);
if ((Row = 0) or (Row = -1)) then
pmUpdateIpAndMac.AutoPopup := False
else
pmUpdateIpAndMac.AutoPopup := True;
end;