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
delphi@carrz-fox-fire.com
{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 --------------------------------------------------------------- Part.1 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
:) _______________________________________________________________ Part.2
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
&Font; --------------------------------------------------------------- TPopupMenu
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 StatusBar1.Invalidate;
OnHint StatusBar1.Panels[2].Text :=
Application.Hint;
OnMessage //This checks for the caps, numlock and insert key presses if
Msg.message = WM_KEYUP then StatusBar1.Invalidate;
OnRestore //paint the caps, num,
ins StatusBar1.Invalidate;
---------------------------------------------------------------------------------------------------------------
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:
var CharPosX,CharPosY:
integer; EM_EXLINEFROMCHAR :integer; begin CharPosY :=
SendMessage(TRichEdit(Sender).Handle, EM_EXLINEFROMCHAR,
0,TRichEdit(Sender).SelStart); CharPosX := (TRichEdit(Sender).SelStart -
SendMessage(TRichEdit(Sender).Handle, EM_LINEINDEX, CharPosY,
0)); Inc(CharPosY); Inc(CharPosX); StatusBar1.Panels[0].Text:=
Format('Line: %d Col: %d', [CharPosY,
CharPosX]); ---------------------------------------------------------------------- Part.3: 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.
var Color: TColor; MyRect:
TRect; begin
MyRect :=
Rect; StatusBar1.Canvas.FillRect(Rect);
case Panel.Index of 3: begin if
GetKeyState(VK_CAPITAL) = 0 then Color := clGray else Color :=
clBlack; end; 4: begin if GetKeyState(VK_INSERT) = 0 then Color
:= clBlack else Color := clGray; end; 5: begin if
GetKeyState(VK_NUMLOCK) = 0 then Color := clGray else Color :=
clBlack; end; end; //end case StatusBar1.Canvas.Font.Color := Color;
DrawText(StatusBar1.Canvas.Handle, PChar(Panel.Text), -1, MyRect, DT_SINGLELINE
or DT_VCENTER or DT_CENTER);
------------------------------------------------------------------ next:
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 begin //this is the start. the default
begin if FontDialog1.Execute then begin 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; end; //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:
var
rc : LongInt;
begin
rc := MessageBox(0, 'You will loose
anything thats not saved! Do you want to continue with this?','War
if rc = mrYes Then
InputKeeper.Lines.Clear;
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.Lines.LoadFromFile(OpenDialog1.FileName); InputKeeper.SelStart
:= 0;
double click Save insert this code : {This will save the current open
file} var sEdit :
String; begin 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 inputKeeper.Lines.SaveToFile(SaveDialog1.Filename);
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'; Application.HelpContext(10);
---------------------------------------------------------------------------------------------
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
OnClose: var Winstate:
integer; begin IniFile.Clear;
if UserTextEditor.WindowState = wsMaximized
then WinState := 1 else WinState := 0;
IniFile.Add(IntToStr(WinState));
IniFile.SaveToFile(ExePath +
'UserTextEditor.ini'); IniFile.Free; (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
OnCreate
var WinState: integer; begin ExePath :=
ExtractFilePath(Application.ExeName); IniFile :=
TStringList.Create;
if FileExists(ExePath +
'UserTextEditor.ini')then begin IniFile.LoadFromFile(ExePath +
'UserTextEditor.ini'); WinState := StrToInt(IniFile.Strings[0]);
if WinState = 1 then UserTextEditor.WindowState :=
wsMaximized else UserTextEditor.WindowState := wsNormal; end;
//their is 2 end; in the
procedure call
OnResize var MinusWidth:
integer; begin MinusWidth := StatusBar1.Panels[0].Width
+ StatusBar1.Panels[1].Width + StatusBar1.Panels[3].Width
+ StatusBar1.Panels[4].Width + StatusBar1.Panels[5].Width
+ StatusBar1.Panels[6].width; StatusBar1.Panels[2].Width :=
StatusBar1.Width - MinusWidth;
---------------------------------------------------------------- Now
over to the TRichEdit Component lets do the same as
above on the Events tab
OnKeyDown
var i: integer; begin if (Shift = [ssShift])
and (Key = VK_F12) then begin for i := 0 to TRichEdit(Sender).Lines.Count
- 1 do TRichEdit(Sender).Lines.Strings[i] := 'document.write("'
+TRichEdit(Sender).Lines.Strings[i] + '");'; end; //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) next 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
var 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 begin 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 begin 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 + '
';
end;
---------------------------------------------------------------------------- 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
:~)
var FileName: String; begin if
PrintDialog1.Execute then InputKeeper.Print(FileName); end;
Now we are going to add the information for the Save As Procedure:
Add the following code un the MainMenu's Save As..... <<<<<<<<<----------------->ook :~)
var FileName : String; begin if
SaveDialog1.Execute
then begin InputKeeper.Lines.SaveToFile(FileName); 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); var nFiles:Integer;
fName:String; FileName: String; begin nFiles:=
DragQueryFile(MSg.Drop,$FFFFFFFF,nil,0);
try if (nFiles > 1)
then
begin
MessageBox(Handle,'Please, drag one file by
time.',
@Caption[1],MB_ICONWARNING or MB_OK);
end else
begin
SetLength(fName,MAX_PATH);
DragQueryFile(Msg.Drop,0,@fName[1],MAX_PATH);
fName:=PChar(fName); if
FileExists(fName) then
begin
FileName:=fName;
InputKeeper.Lines.LoadFromFile(FileName);
end
else
MessageBox(Handle,'Draged file does not
exists.',
@Caption[1],MB_ICONWARNING or MB_OK);
end; finally
DragFinish(Msg.Drop); end; end;
On the Forms OnCreate
add the Following Code:
DragAcceptFiles(Handle,True);
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.
|