有一个这样的例子。<br> unit main;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, ActnList, StdActns, ToolWin, ActnMan, ActnCtrls, ActnMenus,<br> StdCtrls, ImgList, ComCtrls, ExtActns, XPStyleActnCtrls, BandActn,<br> StdStyleActnCtrls;<br><br>type<br> TForm1 = class(TForm)<br> ActionManager1: TActionManager;<br> ActionMainMenuBar1: TActionMainMenuBar;<br> Action1: TAction;<br> Action2: TAction;<br> Action3: TAction;<br> ReopenActionList1: TActionList;<br> Action4: TAction;<br> Action5: TAction;<br> Action6: TAction;<br> Action7: TAction;<br> Action8: TAction;<br> ActionToolBar1: TActionToolBar;<br> ImageList1: TImageList;<br> FileOpen1: TFileOpen;<br> EditCut1: TEditCut;<br> EditCopy1: TEditCopy;<br> EditPaste1: TEditPaste;<br> EditSelectAll1: TEditSelectAll;<br> EditUndo1: TEditUndo;<br> EditDelete1: TEditDelete;<br> RichEditBold1: TRichEditBold;<br> RichEditItalic1: TRichEditItalic;<br> RichEditUnderline1: TRichEditUnderline;<br> RichEditStrikeOut1: TRichEditStrikeOut;<br> RichEditBullets1: TRichEditBullets;<br> RichEditAlignLeft1: TRichEditAlignLeft;<br> RichEditAlignRight1: TRichEditAlignRight;<br> RichEditAlignCenter1: TRichEditAlignCenter;<br> SearchFind1: TSearchFind;<br> SearchFindNext1: TSearchFindNext;<br> SearchReplace1: TSearchReplace;<br> SearchFindFirst1: TSearchFindFirst;<br> FileSaveAs1: TFileSaveAs;<br> FilePrintSetup1: TFilePrintSetup;<br> FileRun1: TFileRun;<br> FileExit1: TFileExit;<br> RichEdit1: TRichEdit;<br> CustomizeActionBars1: TCustomizeActionBars;<br> Action9: TAction;<br> procedure FormCreate(Sender: TObject);<br> procedure FileOpen1Accept(Sender: TObject);<br> procedure ReopenActionExecute(Sender: TObject);<br> private<br> { Private declarations }<br> ReopenMenuItem: TActionClientItem;<br> OpenToolItem: TActionClientItem;<br> procedure FindReopenMenuItem(AClient: TActionClient);<br> procedure FindOpenToolItem(AClient: TActionClient);<br> procedure UpdateReopenItem(ReopenItem: TActionClientItem);<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.FindReopenMenuItem(AClient: TActionClient);<br>begin<br> // Find the Reopen item by looking at the item caption<br> if AClient is TActionClientItem then<br> if Pos('Reopen...', TActionClientItem(AClient).Caption) <> 0 then<br> ReopenMenuItem := AClient as TActionClientItem<br>end;<br><br>procedure TForm1.FindOpenToolItem(AClient: TActionClient);<br>begin<br> // Find the Open item by looking at the item caption<br> if AClient is TActionClientItem then<br> if Pos('Open', TActionClientItem(AClient).Caption) <> 0 then<br> OpenToolItem := AClient as TActionClientItem;<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br><br> procedure SetupItemCaptions(AnItem: TActionClientItem);<br> var<br> I: Integer;<br> begin<br> if Assigned(AnItem) then<br> for I := 0 to AnItem.Items.Count - 1 do<br> TCustomAction(ReopenActionList1.Actions).Caption :=<br> Copy(AnItem.Items.Caption, 5, MaxInt);<br> end;<br><br>begin<br> RichEdit1.Align := alClient;<br> // Find the Reopen... menu item on the ActionMainMenu<br> ActionManager1.ActionBars.IterateClients(ActionManager1.ActionBars[0].Items,<br> FindReopenMenuItem);<br> // Find the Reopen... menu item on the ActionToolBar<br> ActionManager1.ActionBars.IterateClients(ActionManager1.ActionBars[1].Items,<br> FindOpenToolItem);<br> // Set the captions of the actions since they are used to open the file<br> SetupItemCaptions(ReopenMenuItem);<br> SetupItemCaptions(OpenToolItem);<br>end;<br><br>procedure TForm1.FileOpen1Accept(Sender: TObject);<br>var<br> I: Integer;<br> Found: Boolean;<br>begin<br> Found := False;<br> // If the filename is already in the list then do not add it again<br> for I := 0 to ReopenActionList1.ActionCount - 1 do<br> if CompareText(TCustomAction(ReopenActionList1.Actions).Caption,FileOpen1.Dialog.FileName) = 0 then<br> begin<br> Found := True;<br> break;<br> end;<br> if not Found then<br> begin<br> // Update the Reopen menu...<br> UpdateReopenItem(ReopenMenuItem);<br> UpdateReopenItem(OpenToolItem);<br> end;<br> // ...then actually open the file<br> RichEdit1.Lines.LoadFromFile(FileOpen1.Dialog.FileName);<br>end;<br><br>procedure TForm1.UpdateReopenItem(ReopenItem: TActionClientItem);<br>var<br> I: Integer;<br>begin<br> if ReopenItem = nil then<br> exit;<br> // Add thew new filename to the beginning of the list and move other items down<br> for I := ReopenActionList1.ActionCount - 1 downto 0 do<br> if I = 0 then<br> TCustomAction(ReopenActionList1.Actions).Caption := FileOpen1.Dialog.FileName<br> else<br> TCustomAction(ReopenActionList1.Actions).Caption :=<br> TCustomAction(ReopenActionList1.Actions[I - 1]).Caption;<br> // Add new items to the reopen item if necessary<br> if ReopenItem.Items.Count < ReopenActionList1.ActionCount then<br> ReopenItem.Items.Add;<br> // Set the item captions by appending a number for use as the shortcut<br> // This change will cause them to be streamed which allows us to store the<br> // filenames when the application is shutdown<br> for I := 0 to ReopenItem.Items.Count - 1 do<br> begin<br> ReopenItem.Items.Action := ReopenActionList1.Actions;<br> ReopenItem.Items.Caption := Format('&%d: %s', [I,<br> TCustomAction(ReopenActionList1.Actions).Caption]);<br> end;<br>end;<br><br>procedure TForm1.ReopenActionExecute(Sender: TObject);<br>begin<br> // Set the reopened filename into the FileOpen action and call OnAccept to open the file normally<br> FileOpen1.Dialog.FileName := (Sender as TCustomAction).Caption;<br> // Execute the action's OnAccept logic<br> FileOpen1.OnAccept(nil);<br>end;<br><br>end.