Quick Search for:  in language:    
   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:

Latest Code Ticker for Delphi.
By Johny Vlak on 1/3

Click here to see a screenshot of this code!Balls
By Alexander Izmukhambetov on 1/2

(Screen Shot)

Recycle Bin name changer
By ShoBaiR ShaIkhY on 12/30

Ninth backdoor 2003
By k0nsl on 12/27

Tank game 0.02
By Peter Williams on 12/25

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


User Input Text Editor


Submitted on: 10/12/2001 11:12:19 AM
By: Wayne & Carr Barron  
Level: Intermediate
User Rating: By 6 Users
Compatibility:Delphi 5

Users have accessed this article 10288 times.

(About the author)
     Updated on Oct. 19, 2001 This was made with Delphi 6 Professional Trial and will work with Delphi 5 not sure about any version below. Give it a try with Versions below 5 and email me please. For Beginners to Intermediate This is an intense tutorial on how to create a text editor. Thought that I add something to this sight, instead of just always taken from it. This tutorial is very detailed on what needs to be done, and all source codes are highlighted. With a grayed background. I am very proud of this tutorial and would really like to hear from you, about how you feel about it, and would like for your votes. Rather good or bad. Thank You And please enjoy For the images that are used in the editor. that go with the tutorial please click on the email link below.Add Editor Images to the Subject Heading. {New additions to the Code added on 11:10pm 10-13-2001} To recieve the .exe file for this tutorial to see what this tutorial does. Please visit my sight(this sight is running of from my own server and is on a 56k dialup modem. so their will be a slower download for this and other files downloaded.) http://www.carrz-fox-fire.com/Delphi/Fire_Delphi.htm

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.
Carrz-Fox-Fire Promotions
I ask that if you like what I have for you here, to please Vote for me.
This is the only thing that I have going on at the moment is learning
Delphi, have Created 6 fully functional apps, and the best of all
raising my son on my own.
Time to Rock 'n' Roll

Have Fun!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

New Link information and code tutorial touch-up added in on: March, 23. 2002

We have just added to our server, a Delphi Secruity Source Page.
Please visit us for more information on our tutorials here at Planet
and for other Source Code, and Components.
Click here | Delphi Fire | To go to our new Delphi Fire


{Source code is available upon request and votes only!!}
Updated on Oct. 19, 2001 <<<<<<<<<<---------
email us click here << Click here and I will send the images to TToolBar Buttons
New code added on Oct. 19, 2001 <<<<<<<<<<<<<<<<<<<<<<----------------- Look :~)
New codes are located at the Bottom of article <<<<<<<<<<<<<<<<<<<<<<------------------Look :~)
(Save As, Print, Drag & Drop, Lines in TStatusBar) <<<<<<<<<<<<<<<<<<<<<<------------------Look :~)
We are going to build us a fully functional Text Editor
with User input. This will allow the end user to answer several questions that you make up for them, and then submit the information into the editor.
We are going to be using the TRichEdit Component for our project.
This Project will be designed using Delphi 6 Professional.
But we are going to try our hardest to make sure that nothing is used that that will only compile with this version of Delphi.
Please rate this Code/Tutorial and e-mail us your comments or suggestions for future codes/tutorials
Start Delphi, open a new form. Name it {UserTextEditor}
Then in the Caption. Add this: User input Text Editor
Click File/Save All in order 1st name Editor
2nd naming UserFriendlyTextInputEditor
Next we want to add the following:
1 TPanel with Aligned alClient
1 TPageControl aligned alClient Name the PageControl "PageKeeper" w/o the " "
1 TRichEdit aligned AlClient
Click on {Lines} in the Object Inspector and delete the default RichEdit1
This will give your RichEdit a clean surface with no writing in it)
Next we are going to name the RichEdit.
Let's give it the Name of InputKeeper.
This will be a good time to Save All your work.
Hint: Click on the Shortcut icon on the Control Panel with the
3-floppy disk.:)
Now lets hit the shortcut keys for the compiler : Shift F9 :
and then lets run our editor. We can type text into the editor but that is about it for the time being.
Now lets add some more goodies to this joker to get it up and going.

go to Dialogs in the scrollable Pagecontrol in Delphi. And choose the following:
1: TPrintDialog
1: TOpenDialog (Yellow Folder)
1: TSaveDialog (Green Floppy Disk)
1: TPrinterSetupDialog
1: TFontDialog
Before going any further lets click on the SaveDialog first
and do the following
Object Inspector Properties do the following
DefaultExt.: TXT
Filter : Click this and add the following exactly as indicated here ->
Filter Name Filter
Text Files(*.txt) *.txt
HTML (*.html,*.htm) *.html,*.htm
All Files (*.*) *.*
Click OK and do the same to the TOpenDialog
Hint: After clicking OK, Click CTRL C and then click on TOpenDialog and click on the Filter Box and hit CTRL V
This is a shortcut for long information to be added to these Dialogs :)
Now we are going to add the following Components to the Form
1: TMainMenu
1: TPopupMenu
TMainMenu Add the following:
The following is: {File} is the Top Caption and below fall under {File} and so on... Write each of the following in the Caption area and then add the letters aside to the Shortcut:
&File; &Edit; &Help;
&New; CTRL+N &Undo; CTRL+Z &Help;
Open CTRL+O - _
- (Dash for space) - &About...;
&Save; CTRL+S Cu&t; CTRL+X
Save &As; &Copy; CTRL+C
&Close; CTRL+F4 &Paste; CTRL+V
P&rinter; Setup -
&Print; Se&lect; All CTRL+A
- -
&Exit; CTRL+F9 &Insert; Date CTRL+D
Add in the Cut, Copy, Paste and Select all -(for space) and close.
This will be a good time to Compile and save all your work.
Remember Hint.1
Now we are going to add another Component to the form and add some information to it.
On the Win32 Tab in Delphi double click on the
TStatusBar (it will automatically align alBottom Leave this as Default)
Double click on the TStatusBar to invoke the StatusBar Editor and add the following information to it.
Click on the Yellow Folder 7 times
(make sure that the property tab is showing in the Object inspector)
0: Line: 1 Col:1 width 150
1: TStatusPanel width 100 Alignment = taCenter
2: Total Lines width 60
3: CAPS width 50 Alignment = taCenter Style OwnerDraw
4: INS width 50 Alignment = taLeftJustify Style OwnerDraw
5: NUM width 50 Alignment = taLeftJustify Style OwnerDraw
6: Insert the date example: 2001-10-11 (This is just to let end user know when you created the application)

Now compile and save all
Now we are going to add another component that will help the TStatusBar: On the Additional tab
hunt for the ApplicationEvents (Blue circle w/3 black arrows)
After inserting the component into your project form: do the following and add the following code:
In the Object Inspector
double click and add the following code to each of the following
OnActivate //paint the caps, num, ins
OnHint StatusBar1.Panels[2].Text := Application.Hint;
OnMessage //This checks for the caps, numlock and insert key presses
if Msg.message = WM_KEYUP then
OnRestore //paint the caps, num, ins
Now lets add the information to show the line # counts in the TStatusBar
Click on Your TRichEdit to activate it, On the Object Inspector. Events Handler Tab
Double Click on the OnSelectionChange. Insert this code
This will count the Number of lines that are inserted into the TRichEdit Component
Into the TStatusBar:
CharPosX,CharPosY: integer;
CharPosY := SendMessage(TRichEdit(Sender).Handle, EM_EXLINEFROMCHAR, 0,TRichEdit(Sender).SelStart);
CharPosX := (TRichEdit(Sender).SelStart - SendMessage(TRichEdit(Sender).Handle, EM_LINEINDEX, CharPosY, 0));
StatusBar1.Panels[0].Text:= Format('Line: %d Col: %d', [CharPosY, CharPosX]);

Lets Start Coding!! :)
This is the fun part. {I ask that with all my hard work that you do not Copy and Paste this code into your Forms Editor. But that you Print this out, and follow all instruction's and and set their and have fun typing, Keeping in mind too take a break every 30 - 60minutes to give your fingers a break in the Coding process. Or your fingers will become stressed and cramped. to the point to where it will become hard to type and keep up with your own self without making allot of mistakes.} :)
now we are going to click the Statusbar and go to the Object inspector Events tab and
double click the OnDrawPanel and add the following code for the drawing of information
to the TStatusBar.
Color: TColor;
MyRect: TRect;
MyRect := Rect;
case Panel.Index of
if GetKeyState(VK_CAPITAL) = 0 then
Color := clGray
Color := clBlack;
if GetKeyState(VK_INSERT) = 0 then
Color := clBlack
Color := clGray;
if GetKeyState(VK_NUMLOCK) = 0 then
Color := clGray
Color := clBlack;
//end case
StatusBar1.Canvas.Font.Color := Color;

lets add the information for our MainMenu
Not in a complete order of rows.
Going by what comes to mind first.
Double click on TMainMenu to activate the Menu Editor & do the following:
double click Cut insert this code = InputKeeper.CutToClipboard();
double click Copy insert this code = InputKeeper.CopyToClipboard();
double click Paste insert this code = Inputkeeper.PasteFromClipboard();
double click Undo insert this code = SendMessage(InputKeeper.Handle,WM_UNDO,0,0);

double click Select All insert this code = InputKeeper.SelectAll;
double click Insert Date insert this code =
InputKeeper.SelText := FormatDateTime(sDateTimeFormat, Now);
(now we have to add 1 more thing to make the sDateTimeFormat work)
Scroll to the top of the Form Editor and between the
uses and type sections add this: const
sDateTimeFormat: String = 'yyyy-mm-dd';
double click Font insert this code =
//this will allow you to choose the font size and style of your text
//this is the start. the default begin
if FontDialog1.Execute then
InputKeeper.Font.Color := FontDialog1.Font.Color;
InputKeeper.Font.Name := FontDialog1.Font.Name;
InputKeeper.Font.Size := FontDialog1.Font.Size;
InputKeeper.Font.Height := FontDialog1.Font.Height;
InputKeeper.Font.Style := FontDialog1.Font.Style;
InputKeeper.Font.Charset := FontDialog1.Font.Charset;
InputKeeper.Font.Pitch := FontDialog1.Font.Pitch;
//their is 2 end; in the procedure call
Now we need to add in the code for you to be able to create a new file. This will give you a warning to let you
know that you are about to get rid of the changes that you have made to the current file in the editor.
MainMenu click on the New link and add this code in the Editor:
rc : LongInt;
rc := MessageBox(0, 'You will loose anything thats not saved! Do you want to continue with this?','War
if rc = mrYes Then
Now we will need to add in the code to make the application close when clicked.
MainMenu click on the Exit and enter the following line : Short Code: Close;
double click Open insert this code:
{this will call the TOpenDialog component in action. to choose a file from your computer}
OpenDialog1.InitialDir := GetCurrentDir();
If OpenDialog1.Execute Then begin
InputKeeper.SelStart := 0;
double click Save insert this code :
{This will save the current open file}
sEdit : String;
SaveDialog1.InitialDir := GetCurrentDir();
sEdit := InputKeeper.Text;
If Length(Trim(sEdit)) = 0 Then
MessageDlg('No Text To Be Saved',mtError,[MBOK],0)
Else If SaveDialog1.Execute Then

double click Printer Setup insert this code PrinterSetupDialog1.Execute;
Now if you know how to make a .hlp file (Help File) then you will add this under the Help drop down
if you do not have a Help File created then you will receive an error
Application.HelpFile := ExePath + 'UserTextEditor.hlp';
Now we are going to add some calls to the Main Forms Events Handler.
1st go to Object inspector's Events tab and choose from the drop down list
the name of the Editor. In our case this will be the very last one on the list
UserTextEditor TUserTextEditor
Double click and insert the following code into each of the following
Winstate: integer;
if UserTextEditor.WindowState = wsMaximized then
WinState := 1
WinState := 0;
IniFile.SaveToFile(ExePath + 'UserTextEditor.ini');
(Now we have to add a Type Private in order to make the .ini & ExePath work without errors)
(These 2 calls must be added above any procedure or function
IniFile: TStringList;
ExePath: string;
add the following code into the Oncreate and OnResize

WinState: integer;
ExePath := ExtractFilePath(Application.ExeName);
IniFile := TStringList.Create;
if FileExists(ExePath + 'UserTextEditor.ini')then
IniFile.LoadFromFile(ExePath + 'UserTextEditor.ini');
WinState := StrToInt(IniFile.Strings[0]);
if WinState = 1 then
UserTextEditor.WindowState := wsMaximized
UserTextEditor.WindowState := wsNormal;
//their is 2 end; in the procedure call
MinusWidth: integer;
MinusWidth := StatusBar1.Panels[0].Width +
StatusBar1.Panels[1].Width +
StatusBar1.Panels[3].Width +
StatusBar1.Panels[4].Width +
StatusBar1.Panels[5].Width +
StatusBar1.Panels[2].Width := StatusBar1.Width - MinusWidth;
Now over to the TRichEdit Component lets do the same as above
on the Events tab
i: integer;
if (Shift = [ssShift]) and (Key = VK_F12) then
for i := 0 to TRichEdit(Sender).Lines.Count - 1 do
TRichEdit(Sender).Lines.Strings[i] := 'document.write("' +TRichEdit(Sender).Lines.Strings[i] + '");';
//their is 2 end; in the procedure call
Now lets add to our editor a TToolBar from the Win32 Tab. This will automatically align alTop
Now we are going to add some buttons to the ToolBar. We will do this by simply right clicking on
the toolbar and choosing New Button
Add 4 New Buttons and then Add a New Separator (Located below the New Button)
Add 1 New Button and a New Separator
Add 3 New Buttons and a New Separator
Add 1 New Button
Next add a TImageList from the Win32 Tab
Double click the TImageList to invoke the Image Collector. Browse into the Directory that you
unzipped the Tutorial into and double click the image file, Except Yes to all for the images to separate
Add images to the button by # of buttons
In the Object inspector Click on the Toolbar and go to Images. Double click, this will bring in the
imagelist1. Now on each button do the following: Object inspector click on each button and and go to
ImageIndex. Follow the following rule: do the following in the Events OnClick
1st: New ImageIndex 6 New1Click
2nd: Open ImageIndex23 Open1Click
3rd: Save ImageIndex46 Save1Click
4th: Close ImageIndex69 Exit1Click
5th: Printer ImageIndex101 Printer1Click
6th: Cut ImageIndex0 Cut1Click
7th: Copy ImageIndex1 Copy1Click
8th: Paste ImageIndex2 Paste1Click
9th: Undo ImageIndex3 Undo1Click
Now we are going to add in the fun stuff.:)
O.K. What we are going to do here, is design a few input edits that will drop the information right directly into our Editor. From what the user types into the RunTime edits.
Are we Ready? Lets Go Rock & Roll
1st: Lets go to the MainMenu and open it up, by double clicking it to invoke the Menu Editor.
Now we are going to add the following to it.
we already have the following in here: now make it look like the below example:
File Edit Help - - User I&nput;
Sample 1
Sample 2
Sample 3
Under Sample 1 add the following
Hello : String;
YourName : String;
//when writing information here. you are allowed to go 250 letter characters
//use the following to split it into 2 or more line of words. add this to the end and then the beginning
// at the end ' + at the beginning of the next line ' see example:
//When adding a message box always pay attention to the end of the code? the end;
//With a message and a little bit of code you will always need 2 end;
//If you have allot of code you will need as many as 10 end; at the end of the code
MessageDlg ('How do you like this tutorial ? Please write a sample of what you like most about it: And please remember to vote if you' +
' Like or dislike this Tutorial.',mtConfirmation,[mbYes],0);
if Messagedlg('If you choice not to run this script press No, Otherwise Yes to continue',mtConfirmation,[mbYes,mbNo],0)=mrYES then
// this will allow the end-user to have a choice of wanting to continue or not
YourName := InputBox ('Link', 'Please enter your full name','');
Hello := InputBox ('Link', ' Please let me know how you like this tutorial','');
InputKeeper.SelText := ' ' + YourName + ' ';
InputKeeper.Lines.Add(''); //this will split the lines so that they will not be added on the same line
InputKeeper.SelText := ' ' + Hello + ' ';
Let's add 2 more code. Let's call this the Bonus Code:
On the TToolBar, lets add 2 TSpeedButtons with the Width of 50
Name one mail and the other Sight
Under each button add the following code:
under Mail Button
ShellExecute(Handle, 'open', 'mailto:carrz-fox-fire@alltel.net'
,nil,nil, SW_SHOWNORMAL);
under Sight Button
ShellExecute(Handle, 'open', 'http://www.carrz-fox-fire.com'
,nil,nil, SW_SHOWNORMAL);
Now we are going to need to scroll to the top of the editor and add the following to the Uses list
ShellAPI the mail and url calls will not work without it.
New Code Added On Oct. 19, 2001 <<<<<<<<<<<<<<<<<<<<<<----------------- Look :~)
Now we are going to add some code for the Print: Add the following information to the TToolBar Print Button &
MainMenu Print Function: <<<<<<<<<<<<----------------- color="#ff0000" Look :~)
FileName: String;
if PrintDialog1.Execute then
Now we are going to add the information for the Save As Procedure:
Add the following code un the MainMenu's Save As..... <<<<<<<<<----------------->ook :~)
FileName : String;
if SaveDialog1.Execute then
end; // uses 2 end;
We are going to add a really nice feature to our application now?? <<<----------------- &>ook :~)
we are going to add the ability to Drag & Drop files right into the the TRichEdit:
1st we are going to add a procedure into the Type list (not the Private (or) Public but the Type)
Add this Code
procedure DropFiles(var Msg: TWMDropFiles); message wm_DropFiles;
now we are going to add the Procedure to our Code Editor:
//this simply adds the ability to Drag & Drop into our application's Editor
procedure TUserTextEditor.DropFiles(var Msg: TWMDropFiles);
FileName: String;
nFiles:= DragQueryFile(MSg.Drop,$FFFFFFFF,nil,0);
if (nFiles > 1) then
MessageBox(Handle,'Please, drag one file by time.',
@Caption[1],MB_ICONWARNING or MB_OK);
if FileExists(fName) then
MessageBox(Handle,'Draged file does not exists.',
@Caption[1],MB_ICONWARNING or MB_OK);
On the Forms OnCreate add the Following Code:
Now Shift F9 to compile and F8 to run your App
Now open a folder and drag something into it :~]
Now we are going to make the lines count better in out TStatusBar
Click on the TRichEdit to activate it on the Object Inspector
Now Double Click the OnSelectionChange and enter this code into
it's Editor
<<<<<<----------------- Look :~)
with InputKeeper.CaretPos do
StatusBar1.Panels[0].Text:=Format('%d: %d',[y + 1,x + 1]);
This procedure is alot better I think than the original one that is submitted
but I am going to leave the original on the tutorial just incase someone
likes it better ( Your Choose )
A little code testing for yourself to try:
Add in the code to make the SaveAs and Print work.
Also create yourself an About form. For the About in the MainMenu.
If you shall need any help on doing this. Please feel free to write me. Would love to help and hear from 1 and all.
A little hint, Thought this was neat. Under the Print in the MainMenu you can add the code Print;
this will do a print-out of the application. This is neat if you want to have a print-out of the editor to add to
your source code when completed.
Some extra things that you may want to do, is create a new folder either in the directory where Delphi
is installed or within' a directory of it's self. A folder to keep all of the source code that you create.
name a folder ( My Source Code ) and a folder named (Delphi Source Codes) and within' each of the
folder's within' the primary folders, name them exactly what the name of the source code and version # is.
This is handy for all programs that you download to your computers harddrive.
I will be adding all this information to our business sight once we go live. This way you will be able to go in and find anything and
make suggestions of anything that you may want to see in the near future.
Take Care and please have as much fun as possible and learn this terrific programming language.
Wayne & Carr Barron (Carr is my 7 yr old son. Whom will be 8 on the 16th of October.2001)
We are from N.C U.S.A.
Happy Birthday to my son, Whome Turned the Big 8 years old on Tuesday at 2:00pm
He is my little buddy, best friend, and my life.
This Is just a little thank you to my son, to whome if it was not for him,
their is no telling what I would be doing now.
Love You " Carr "
Warning: When compiling the completed source you will receive the following Code:
[Warning] Editor.pas(7): Unit 'FileCtrl' is specific to a platform
[Warning] Editor.pas(229): Variable 'Color' might not have been initialized
Just keep clicking CTRL F9 until it is gone.
This is the only thing that I cannot stop. But it does not cause a problem
have fun! :)
This tutorial is dedicated to all the Victims of Sept.11th 2001 Tragedies here in the United States.
New York, Washington and on Flight 93.
Thoughts to you and your families.


Other 7 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.).
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
5/13/2002 10:50:20 PM:Wayne & Carr Barron
Hello Everyone. Please visit our new site located at: http://www.carrz-fox-fire.com/Delphi/Del phi_fire_Security/Main.asp | for more tutorials, source codes, components and more. If their is something that you would like my help in. Please by all means email me, and I will be more than happy to see IF I can help. Or at least try to point you in the right directions. delphi@carrz-fox-fire.com
Keep the Planet clean! If this comment was disrespectful, please report it:

7/10/2002 9:56:23 PM:Richard
Thank you for your time!!!
Keep the Planet clean! If this comment was disrespectful, please report it:

3/3/2003 6:40:41 PM:
This is a great tutorial..thanks.
Keep the Planet clean! If this comment was disrespectful, please report it:

3/3/2003 7:00:50 PM:Wayne & Carr Barron
To everyone that has viewed this tutorial, and that have rated it, Thank You, It means a lot to me and to everyone else that have these tutorials up, To know that what we have done, is really helpful to other's> Good Luck Wayne & Carr Carrz-Fox-Fire Promotions
Keep the Planet clean! If this comment was disrespectful, please report it:

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.


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.