This web page is to help a beginner build a text editor!
Bold
CurrText.Style := CurrText.Style + [fsBold]; Regular CurrText.Style := CurrText.Style - [fsBold]; |
To insert the Date and Time in a
Editor:
procedure TForm1.Date1Click(Sender: TObject);
|
Paste from Clipboard:
procedure TForm1.Paste1Click(Sender: TObject);
|
Copy to the Clipboard:
procedure TForm1.Copy1Click(Sender: TObject);
|
Cut to the Clipboard:
Editor.CutToClipboard;
|
Editor Alignments. Left - Right -
Center.
begin Editor.Alignment := taLeftJustify; end; begin Editor.Alignment := taRightJustify; end; begin Editor.Alignment := taCenter; end; |
Counting Characters in a text file
(Editor).Using
a Dialog.
begin MessageDlg (Format ( 'The text has %d characters', [Memo1.GetTextLen]), mtInformation, [mbOK], 0); end; |
SetFocus:
Editor.SetFocus;
|
Changing a Editor colour. Using the
ColorDialog:
begin
|
Positioning the Caret in a Editor:
procedure TForm1.Button1Click(Sender: TObject);
0 is the first character. |
Using Quick Reports for a Text
Editor Preview
(Simple
Example).
First drop a TQuickRep on a Form,
Form3.QRMemo1.lines := Editor.Lines;
|
To get a Text Editor to load a text
file when
your Text Editor is associated with your systems *.txt files.
procedure TForm1.FormShow(Sender: TObject);
|
This will put the opened files name on the taskbar button and
shows
you how to use ExtractFileName .
Application.Title := ExtractFileName(OpenDialog.FileName); |
Memo1.Lines.LoadFromFile('c:\ssapcs\desktop1\config1.txt'); end; { Your text file will be in a directory (Folder) that you want to load } Next DoubleClick on Button1 and type this code begin
Run Project1 (Or whatever you called it), now you
should be
able to see the text from
Hows that for easy!
Part 2 Saving the Memo lines to a text file is simple. Put 3 Buttons on Form1, keep Memo1 on
the Form.
procedure TForm1.OpenClick(Sender: TObject);
Double-Click on the button named 'Save', write this code between 'begin' and 'end' procedure TForm1.SaveClick(Sender: TObject);
Double-Click on the button named 'Clear', write this code between 'begin' and 'end' procedure TForm1.ClearClick(Sender: TObject);
Note the names of the procedures. In the Object Inspector set the 'Save' Button to Enabled := False; Make sure you use the path to a file that exists and you
don't mind
editing this file.
Part 3 A Simple Text Editor This was made with Delphi 3, with a few
small
changes it should work on all versions of Delphi.
|
Links: