Whenever something is created there come the time when this something must be upgraded, same must work with our text editor.
Now let's see what we have.
Your form in non-run mode must look something like this more or less, well.

We have there File and Edit menu, we have the speed bar menu, and else our program understands the most common txt format.
OK, From here and now what do you think must be added here? Most of the programs, no, all of the programs has the Help menu.
Talking about text editing, there must be some more options than just cutting, copying or pasting.
Let's say – font, text size, coloring your text.
I think there is a point of adding all this.
And a bit of paint here, and there…
Let's start from editing of main menu, it the most important one as you can guess.
Find an icon on your form like this:

double click on it with your blessed mouse.
After this a window pops out.
I think you do remember what that thing for, don't you? Wonderful! That what I wanted to hear, so let's get to our preparation steps.
You remember that at the beginning application wizard kindly created for us the File and Edit menus and all what was left for us is just fill the content with some meaning.
Now we have to prepare the two menus by ourselves after what we'll fill the frame with some paints.
Now you can see the main menu editor right? By the right side of the Edit menu item you have a dotted square, click on it and then in Caption field of OI input: Fo&rmat

No! That's not a typo.
Yeah I'm talking about that "&" symbol in Format word.
If you will examine all other menu items you will see that that small thing is everywhere.
It says that the next letter of the name in which it was included is going to be a shortcut letter and that letter becomes underlined.
Now when you have created the main menu item create its items.
First will be Align with its own submenus.
To create submenu click with left mouse button on Align and select "Create Submenu"

After this create three items Left, Center and Right

After that create same menu items as shown on pictures:


And we will need two more things on our form to be added.
That will be those invisible components I was talking about last time.
We'll need Font Dialog and Find Dialog that can be found on Dialogs tab of VCL


That's it! Our frame is ready now let's fill the pie with some sort of jam.
Bang! Boom! Badum!
First we need to create some handlers for our Align menu.
You have already started to think that we have to write onClick event handler for all three of them (Left, Center and Right)? Nothing like this!
Create an onClick handler by double clicking on any of three submenus after what rename the procedure from
code #01:
line #01: procedure TMainForm.Left1Click(Sender: TObject);
|
to
code #02:
line #01: procedure TMainForm.AlignSelectClick(Sender: TObject);
|
And there is another place where
code #03:
line #01: procedure Left1Click(Sender: TObject);
|
must be changed in to
code #04:
line #01: procedure AlignSelectClick(Sender: TObject);
|
You will find it at the beginning of you source code

Then between begin and end type this code of the procedure body input this code:
code #05:
line #01: Left1.Checked := False; line #02: Right1.Checked := False; line #03: Center1.Checked := False;
line #04: with Sender as TMenuItem do Checked := True; line #05: with RichEdit1.Paragraph do line #06: if Left1.Checked then line #07: Alignment := taLeftJustify
line #08: else if Right1.Checked then
line #09: Alignment := taRightJustify
line #10: else if Center1.Checked then
|
And we are not finished jet.
In the main menu constructor select each on the Align sub items and in event tab of OI for onClick event choose AlignSelectClick handler.
Enough here lets create the Word Wrap procedure now.
Double click on the Word Wrap item if you're in main menu constructor or click once if you're at the form constructor now.
The procedure must be generated automatically.
Then input the following code:
code #06:
line #01: procedure TMainForm.WordWrap1Click(Sender: TObject); line #02: begin line #03: RichEdit1.WordWrap:= not RichEdit1.WordWrap; line #04: WordWrap1.Checked:=RichEdit1.WordWrap; line #05: end;
|
Next step is Font editing. It's not going to be hard neither.
Create the handler for Font item menu as I showed it to you before.
This is the code that you must have there:
code #07:
line #01: procedure TMainForm.Font1Click(Sender: TObject);
line #02: begin
line #03: FontDialog1.Font := RichEdit1.Font;
line #04: if FontDialog1.Execute then
line #05: RichEdit1.SelAttributes.Assign(FontDialog1.Font);
line #06: end;
|
Find it yourself!
"How do you think, sir," - asks Dr. Watson: "what educational institution did I graduate from?"
"Elementary, Watson, elementary…" – replied Holms.
We are going to the tastiest thing in our application – I'm talking about find function.
Create the handler and input the following code:
code #08:
line #01: procedure TMainForm.Find1Click(Sender: TObject);
line #02: begin line #03: with FindDialog1 do begin
line #04: Options:=Options+[frHideMatchCase]+[frHideWholeWord]+[frHideUpDown];
line #05: Execute; line #06: end; line #07: end;
|
Do you think that's it? Ha! Ha! We have much more work to do.
Select the FindDialog1 and in Event tab of the OI create onFind handler procedure.
The input the following code:
code #09:
line #01: procedure TMainForm.FindDialog1Find(Sender: TObject);
line #02: var
line #03: FoundAt: LongInt;
line #04: StartPos, ToEnd: Integer;
line #05: begin
line #06: with RichEdit1 do
line #07: begin
line #08: if SelLength <> 0 then StartPos := SelStart
line #09: else StartPos := 0;
line #10: if SelLength <> 0 then
line #11: ToEnd := Length(Text) - StartPos
line #12: else ToEnd := SelLength;
line #13: FoundAt := FindText(FindDialog1.FindText, StartPos, ToEnd, [stMatchCase]);
line #14: if FoundAt <> -1 then
line #15: begin
line #16: SetFocus;
line #17: SelStart := FoundAt;
line #18: SelLength := Length(FindDialog1.FindText);
line #19: end;
line #20: end;
line #21: end;
|
Yes! That is the searching procedure.
Something new here, isn't it? We've just declared some local variables.
Between var and begin there are FoundAt, StartPos and ToEnd variables declared.
Last splines of the model
We have to things left to do. It's about box and help.
Go File -> New -> Other -> Forms -> About box.
Then click twice on OK button and type: Hide; right between begin and end.
Then create handler for About item of main menu with following code within.
code #10:
line #01: procedure TMainForm.About1Click(Sender: TObject);
line #02: begin
line #03: AboutBox.Show;
line #04: end;
|
And now let's add RTF extension.
Click on you OpenDialog and in its properties find Filter.
Double click it and fill it like shown in picture:

That's it.
Your editor is finished now.
You will ask what about help.
To do it we need hlp file.
I'm not going to teach you how to create those, you have internet for this.
I'm going to show only the implementation of help handler.
That going to be the code:
Code #11:
line #01: procedure TMainForm.Help2Click(Sender: TObject);
line #02: begin
line #03: ShellExecute(Application.Handle,'open','help.hlp',nil,nil,0);
line #04: end;
|
As you can see this thing is calling help.hlp file.
For now its ended next step we're going to do something new.
I think media player is going be good.
See you in Step Three.
[via TechFob,by Izes Alhasov]