Simple text editor (Delphi source code)

Source: Internet
Author: User

A simple text editor is designed to create, edit, and save common text files.

Unit U nit1;

Interface

Uses
Windows, messages, sysutils, variants, classes, graphics, controls, forms,
Dialogs, stdctrls, extctrls;

Type
Tform1 = Class (tform)
Panel1: tpanel;
Memo1: tmemo;
Opendialog1: topendialog;
Savedialog1: tsavedialog;
Button1: tbutton;
Button2: tbutton;
Button3: tbutton;
Button4: tbutton;
Button5: tbutton;
Button6: tbutton;
Button7: tbutton;
Procedure button1click (Sender: tobject );
Procedure button2click (Sender: tobject );
Procedure button3click (Sender: tobject );
Procedure button4click (Sender: tobject );
Procedure button5click (Sender: tobject );
Procedure button6click (Sender: tobject );
Procedure button7click (Sender: tobject );
Private
{Private Declarations}
Public
{Public declarations}
End;

VaR
Form1: tform1;
VaR
F: textfile;
Wfilename: string;
Flag: Boolean;

Implementation

{$ R *. DFM}

Procedure tform1.button1click (Sender: tobject );
Begin
Assignfile(f,'newfile.txt ');
Form1.caption: Response 'newfile.txt ';
Wfilename: Invalid 'newfile.txt ';
Rewrite (f );
Memo1.enabled: = true;
Button1.enabled: = false;
Button2.enabled: = false;
Button3.enabled: = false;
Button4.enabled: = true;
Button5.enabled: = true;
Button6.enabled: = true;
Button7.enabled: = true;
Closefile (f );
End;

Procedure tform1.button2click (Sender: tobject );
VaR
Line: string;
Begin
If opendialog1.execute then
Begin
Assignfile (F, opendialog1.filename );
Reset (f );
Form1.caption: = opendialog1.filename;
Memo1.enabled: = false;
Flag: = true;
While not EOF (f) Do
Begin
Readln (F, line );
Memo1.lines. Add (line );
End;
Button1.enabled: = false;
Button2.enabled: = false;
Button3.enabled: = false;
Button4.enabled: = false;
Button5.enabled: = false;
Button6.enabled: = true;
Button7.enabled: = true;
Closefile (f );
End;
End;

Procedure tform1.button3click (Sender: tobject );
VaR
Line: string;
Begin
If opendialog1.execute then
Begin
Wfilename: = opendialog1.filename;
Assignfile (F, wfilename );
Form1.caption: = wfilename;
Reset (f );
Memo1.enabled: = true;
While not EOF (f) Do
Begin
Readln (F, line );
Memo1.lines. Add (line );
End;
Button1.enabled: = false;
Button2.enabled: = false;
Button3.enabled: = false;
Button4.enabled: = true;
Button5.enabled: = true;
Button6.enabled: = true;
Button7.enabled: = true;
Closefile (f );
End;
End;

Procedure tform1.button4click (Sender: tobject );
VaR
I, lastline: integer;
Begin
Lastline: = memo1.lines. Add ('')-1;
Assignfile (F, wfilename );
Rewrite (f );
For I: = 0 to lastline do
Begin
Write (F, memo1.lines [I]);
End;
Closefile (f );
End;

Procedure tform1.button5click (Sender: tobject );
VaR
I, lastline: integer;
Writefile: textfile;
Begin
If savedialog1.execute then
Begin
Wfilename: = savedialog1.filename;
Assignfile (writefile, wfilename );
Rewrite (writefile );
Form1.caption: = wfilename;
Lastline: = memo1.lines. Add ('')-1;
For I: = 0 to lastline do
Begin
Writeln (writefile, memo1.lines [I]);
End;
Closefile (writefile );
End;
End;

Procedure tform1.button6click (Sender: tobject );
VaR
I: integer;
Begin
If not flag then
I: = messagedlg ('Save file? ', Mtconfirmation, mbyesnocancel, 0 );
If I <> 2 then
Begin
If I = 6 then
Button4click (sender );
Memo1.clear;
Form1.caption: = '';
Memo1.enabled: = false;
Button1.enabled: = true;
Button2.enabled: = true;
Button3.enabled: = true;
Button4.enabled: = false;
Button5.enabled: = false;
Button6.enabled: = false;
Button7.enabled: = true;
End;
Flag: = false;
End;

Procedure tform1.button7click (Sender: tobject );
Begin
Close;
End;

End.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.