unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Db, Grids, DBGrids, DBTables, Menus;
type
TSave = procedure(Sender: TObject) of Object;
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
procedure Save(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Save(Sender: TObject);
var
OpenDlg: TOpenDialog;
begin
OpenDlg := TOpenDialog.Create(Self);
OpenDlg.Execute;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
myPopupMenu: TPopupMenu;
myMenuItem: TMenuItem;
i: integer;
p: TPoint;
begin
myPopupMenu := TPopupMenu.Create(Self);
for i := 1 to 3 do
begin
myMenuItem := TMenuItem.Create(myPopupMenu);
myMenuItem.Tag := i;
case i of
1: myMenuItem.Caption := '新建';
2: begin
myMenuItem.Caption := '保存';
myMenuItem.OnClick := Save;
end;
3: myMenuItem.Caption := '删除';
end;
myPopupMenu.Items.Add(myMenuItem);
end;
GetCursorPos(p);
myPopupMenu.Popup(p.x,p.y)
end;
end.