Plan a simple text editor with the ability to build, compile, and survive trivial 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:= ' Newfile.txt ';
wfilename:= ' 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) does
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) does
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.
Reprint must declare: http://pc100.diandian.com/
"Reproduced from: Simple text editor (Delphi Source) [Delphi]".
Jiang Yiven This editor (Delphi Source)