菜单的历史信息

本例效果图:

菜单的历史信息

unit Unit1;



interface



uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, Menus;



type

  TForm1 = class(TForm)

    MainMenu1: TMainMenu;

    OpenDialog1: TOpenDialog;

    mniFile: TMenuItem;

    mniOpen: TMenuItem;

    N1: TMenuItem;

    mniExit: TMenuItem;

    procedure mniOpenClick(Sender: TObject);

    procedure alert(Sender: TObject);

  end;



var

  Form1: TForm1;



implementation



{$R *.dfm}





procedure TForm1.alert(Sender: TObject);

begin

  if Sender is TMenuItem then

    ShowMessage(TMenuItem(Sender).Caption);

end;



procedure TForm1.mniOpenClick(Sender: TObject);

var

  mni: TMenuItem;

  event: TNotifyEvent;

begin

  if not OpenDialog1.Execute then Exit;



  mni := TMenuItem.Create(Self);

  mni.Caption := OpenDialog1.FileName;

  event := alert;

  mni.OnClick := event;



  MainMenu1.Items.Items[0].Insert(2, mni);



  if MainMenu1.Items.Items[0].Count = 4 then

  begin

    mni := TMenuItem.Create(Self);

    mni.Caption := '-';

    MainMenu1.Items.Items[0].Insert(3,mni);

  end;

end;



end.


 
   

你可能感兴趣的:(菜单)