Модератор: Модераторы

type
   TPopupCell = record
     Col,
     Row: Integer;
   end;
  TForm1 = class(TForm)
  ...
    procedure PopupMenu1Popup(Sender: TObject);
  private
    LastPopupInvoker: TStringGrid;
    PopupCell: TPopupCell;
  ...
  end;
...
...
procedure TForm1.PopupMenu1Popup(Sender: TObject);
var
  c: TControl;
  p: TPoint;
begin
  c := Application.GetControlAtMouse;
  if not (c is TStringGrid) then begin
    LastPopupInvoker := nil;
    exit;
  end;
  LastPopupInvoker := TStringGrid(c);
  p := LastPopupInvoker.ScreenToClient(PopupMenu1.PopupPoint);
  LastPopupInvoker.MouseToCell(p.X, p.Y, PopupCell.Col, PopupCell.Row);
end; 
procedure TForm1.StringGridContextPopup(Sender: TObject; MousePos: TPoint; var Handled: Boolean);
begin
  Handled := False;
  if not (Sender is TStringGrid) then begin
    LastPopupInvoker := nil;
    exit;
  end;
  LastPopupInvoker := TStringGrid(Sender);
  LastPopupInvoker.MouseToCell(MousePos.X, MousePos.Y, PopupCell.Col, PopupCell.Row);
end; 

procedure TForm1.MenuItem1Click(Sender: TObject);
var
  aRow, aCol: integer;
  sg: TStringGrid;
begin
  if (Sender is TMenuItem) and
     (TMenuItem(Sender).GetParentMenu is TPopupMenu) and
     (TPopupMenu(TMenuItem(Sender).GetParentMenu).PopupComponent is TStringGrid) then
  begin
    sg := TStringGrid(TPopupMenu(TMenuItem(Sender).GetParentMenu).PopupComponent);
    aRow := sg.Row;  // это неправильно. А как через MouseToCell получить номер строки и столбца, я не понял
    aCol := sg.Col;
    ...
  end;
end;
procedure TpsForm1.MenuItem1Click(Sender: TObject);
var
  aRow, aCol: integer;
  sg: TStringGrid;
  pm: TPopupMenu;
  p: TPoint;
begin
  if (Sender is TMenuItem) and
     (TMenuItem(Sender).GetParentMenu is TPopupMenu) and
     (TPopupMenu(TMenuItem(Sender).GetParentMenu).PopupComponent is TStringGrid) then
  begin
    pm := TPopupMenu(TMenuItem(Sender).GetParentMenu);
    sg := TStringGrid(pm.PopupComponent);
    p := sg.MouseToCell(sg.ScreenToClient(pm.PopupPoint));
    aCol := p.X;
    aRow := p.Y;
    ...
  end;
end;
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 1