The Format menu in our sample application is the simplest menu. It consists of only two commands: Word Wrap and Font.
Figure 16-15: The Format menu
The Word Wrap command enables the user to wrap text at the right margin. If Word Wrap is checked, you should only enable vertical scrolling of the contents of the editor. If Word Wrap is unchecked, you have to display both scroll bars because long lines aren't wrapped at the right margin.
To create the Word Wrap action, follow these steps:
Create a new action and set its AutoCheck property to True to have it automatically toggle its Checked state.
Set the Caption property to &Word Wrap.
Set the Checked property to True because the WordWrap property of the editor is True by default.
Rename the action WordWrapAction.
Finally, write the following OnExecute event handler:
procedure TMainForm.WordWrapActionExecute(Sender: TObject); const SCROLLS: array[Boolean] of TScrollStyle = (ssBoth, ssVertical); begin Editor.WordWrap := WordWrapAction.Checked; Editor.ScrollBars := SCROLLS[Editor.WordWrap]; end;
To create the Format ® Font command, first drop a TFontDialog component on the Designer Surface and then create a new action. Set the Caption of the new action to &Font, rename the action FontAction, and then write the following code in its OnExecute event handler:
procedure TMainForm.FontActionExecute(Sender: TObject); begin { display current font in the dialog box } FontDialog1.Font.Assign(Editor.Font); { change the font } if FontDialog1.Execute then Editor.Font.Assign(FontDialog1.Font); end;