随笔 - 2146  文章 - 97 评论 - 11767 trackbacks - 253

本例效果图:


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.

posted on 2008-04-28 21:52  万一  阅读(...)  评论(...编辑  收藏