自動建立一個 SDI Application 程序, 程序包含了漂亮的菜單:
在窗體文件內記錄著菜單數據:
object MainMenu1: TMainMenu
Images = ImageList1
Left = 8
Top = 152
object File1: TMenuItem
Caption = '&File'
Hint = 'File related commands'
object FileNewItem: TMenuItem
Action = FileNew1
end
object FileOpenItem: TMenuItem
Action = FileOpen1
end
object FileSaveItem: TMenuItem
Action = FileSave1
end
object FileSaveAsItem: TMenuItem
Action = FileSaveAs1
end
object N1: TMenuItem
Caption = '-'
end
object FileExitItem: TMenuItem
Action = FileExit1
end
end
object Edit1: TMenuItem
Caption = '&Edit'
Hint = 'Edit commands'
object CutItem: TMenuItem
Action = EditCut1
end
object CopyItem: TMenuItem
Action = EditCopy1
end
object PasteItem: TMenuItem
Action = EditPaste1
end
end
object Help1: TMenuItem
Caption = '&Help'
Hint = 'Help topics'
object HelpAboutItem: TMenuItem
Action = HelpAbout1
end
end
end
菜單是一個 TMainMenu 類型的對象; 每一個菜單項都是一個 TMenuItem 類型的對象. 單元文件中有聲明:
MainMenu1 : TMainMenu;
File1 : TMenuItem;
FileNewItem : TMenuItem;
FileOpenItem : TMenuItem;
FileSaveItem : TMenuItem;
FileSaveAsItem: TMenuItem;
N1 : TMenuItem;
FileExitItem : TMenuItem;
Edit1 : TMenuItem;
CutItem : TMenuItem;
CopyItem : TMenuItem;
PasteItem : TMenuItem;
Help1 : TMenuItem;
HelpAboutItem : TMenuItem;
看來學習 TMainMenu 類, 必須同時學習 TMenuItem 類; 因為菜單是由若干菜單項(TMenuItem)構成的.