CodePudding user response:
unit Unit1;for the open text files,
Interface
USES the
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
Type
TForm1=class (TForm)
For: TButton;
Button2: TButton;
Memo1: TMemo;
OpenDialog1: TOpenDialog;
Procedure Button1Click (Sender: TObject);
Procedure Button2Click (Sender: TObject);
Private
{Private declarations}
TextName: string;//global variables to save the file
Public
{Public declarations}
end;
Var
Form1: TForm1;
Implementation
{$R *. DFM}
Procedure TForm1. Button1Click (Sender: TObject);
The begin
OpenDialog1. FileName:=' ';
Opendialog1. InitialDir:=sPath;
Opendialog1. Filter:='| text file *. TXT';
If OpenDialog1. Execute then
The begin
TextName:=OpenDialog1. FileName;
Memo1. Lines. LoadFromFile (TexxtName);//open the file
The end;
end;
Procedure TForm1. Button2Click (Sender: TObject);
The begin
Memo1. Lines. SaveToFile (TexxtName);//save the file
end;
End.
Button2, through the Memo after modify text files, formerly known as save the file,