Quick Search for:  in language:    
Heres,code,create,your,editor
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
Delphi Stats

 Code: 209,911. lines
 Jobs: 14. postings

 How to support the site

 
Sponsored by:

 
You are in:
 

Does your code think in ink?
Login





Latest Code Ticker for Delphi.
Record From Microphone to Wave File
By Una-Rat on 11/25


List Manager
By james hill on 11/17


Click here to see a screenshot of this code!Skin app
By Jonathan Curry on 11/15

(Screen Shot)

Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!

Affiliate Sites



 
 
   

Delphi Text Editor Code

Print
Email
 

Submitted on: 7/9/2000 6:06:44 PM
By:  
Level: Intermediate
User Rating: By 8 Users
Compatibility:Delphi 5, Delphi 4, Pre Delphi 4

Users have accessed this article 18568 times.
 
 
     Here's all the code to create your own editor!

 
 
Terms of Agreement:   
By using this article, you agree to the following terms...   
1) You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this article from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.

 

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);
begin
    Editor.SelText := (FormatDateTime('ddd, mmm d, yyyy ', Now));
end;
procedure TForm1.Time1Click(Sender: TObject);
begin
    Editor.SelText := (FormatDateTime('hh:mm AM/PM ', Now));
end;
 

Paste from Clipboard:

procedure TForm1.Paste1Click(Sender: TObject);
begin
    Editor.PasteFromClipboard;
end;
 

Copy to the Clipboard:

procedure TForm1.Copy1Click(Sender: TObject);
begin
    Editor.CopyToClipboard;
end;
 

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;
Memo1.SetFocus;
etc...
 

Changing a Editor colour. Using the ColorDialog:

begin
    ColorDialog1.Color := Editor.Color;
  if ColorDialog1.Execute then
    Editor.Color := ColorDialog1.Color;
end;
 

Positioning the Caret in a Editor:

procedure TForm1.Button1Click(Sender: TObject);
begin
    Editor.SetFocus;
    Editor.SelStart  :=  2;
end;

0 is the first character.

Using Quick Reports for a Text Editor Preview (Simple Example).

First drop a TQuickRep on a Form,
Put a DetailBand on it,
Then drop a TQRMemo on the DetailBand.

Form3.QRMemo1.lines := Editor.Lines;
Form3.QuickRep1.Preview;

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);
begin
    if (ParamCount > 0) and FileExists(ParamStr(1)) then
      Form1.Memo1.Lines.LoadFromFile(ParamStr(1));
end;

This will put the opened files name on the taskbar button and shows you how to use ExtractFileName .
Application.Title := ExtractFileName(OpenDialog.FileName);
Loading a text file into a TMemo
  1. First start a new project.
  2. Place Memo1 (TMemo) on Form1
  3. Set Memo1 Align to alBottom
  4. Place Button1 (TButton) on Form1 at the top of Form1
  5. Click on Form1 and in the Object Inspector click on Events
  6. DoubleClick on OnCreate
  7. Type in this code:
begin
    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
    Memo1.Clear;
end;

 Run Project1 (Or whatever you called it), now you should be able to see the text from
 c:\ssapcs\desktop1\config1.txt  in Memo1.
 Click on Button1 and Memo1 will clear.

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.
Name the first Button 'Open', name the second Button  'Save' and
name the third Button 'Clear'.
Double-Click on the button named 'Open', write this code between 'begin' and 'end'

procedure TForm1.OpenClick(Sender: TObject);
begin
  Memo1.Lines.LoadFromFile('c:\ssapcs\desktop1\config1.txt');
  Save.Enabled := True;
end;

Double-Click on the button named 'Save', write this code between 'begin' and 'end'

procedure TForm1.SaveClick(Sender: TObject);
begin
  Memo1.Lines.SaveToFile('c:\ssapcs\desktop1\config1.txt');
end;

Double-Click on the button named 'Clear', write this code between 'begin' and 'end'

procedure TForm1.ClearClick(Sender: TObject);
begin
  Memo1.Clear;
end;

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.
Run the program, click on the open button add some text to the Memo then click on the save button, click on the clear button and open the file again.


Part 3

A Simple Text Editor

Here is a simple text editor that uses a Memo and four buttons, the OpenDialog, and the SaveDialog.

This was made with Delphi 3, with a few small changes it should work on all versions of Delphi.
Study it carefully, this program will open a file, then you can edit the file then save the file or clear the memo and start again. Also a Close button is included to close the program.
If you want to add to this text editor program have a look at our Delphi Tips web page for some code and ideas.

Download here - Download.


Other 31 submission(s) by this author

 

 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this article(in the Intermediate category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
2/19/2001 12:27:44 AM:Mike Tomte
Good code. I used it as the basic framework for PHP Magic =) I rate it excellent, as it help newbies like me.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
1/13/2003 6:56:47 PM:
Do you send this code to me? (i can't load)
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
1/27/2003 1:54:07 AM:
This link url's is not running this page cannot find on xoom.Please upload this code. http://www.planetsourcecode.com/v b/scripts/ShowCode.asp?txtCodeId=64&lngW Id=7
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
6/21/2003 3:38:59 PM:Scott Armstrong
Great code. There's stuff in there that I didn't even know a text editor could have.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this article has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular article, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | Delphi Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.