mainunit.pas
上传用户:psxgmh
上传日期:2013-04-08
资源大小:15112k
文件大小:2k
- unit mainunit;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls;
- type
- TForm1 = class(TForm)
- Button1: TButton;
- GroupBox1: TGroupBox;
- Memo1: TMemo;
- Label1: TLabel;
- Button2: TButton;
- Button3: TButton;
- Button4: TButton;
- OpenDialog1: TOpenDialog;
- procedure Button1Click(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure Button2Click(Sender: TObject);
- procedure Button3Click(Sender: TObject);
- procedure Button4Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- ATextFile:TextFile;
- implementation
- {$R *.dfm}
- procedure TForm1.Button1Click(Sender: TObject);
- begin
- With OpenDialog1 do
- if execute then
- begin
- Label1.Caption:='当前打开的文件:'+FileName;
- if FileName<>'' then
- begin
- AssignFile(ATextFile,Opendialog1.FileName);
- ShowMessage('文件文件变量和具体的磁盘文件成功建立关联');
- Button2.Enabled:=True;
- Memo1.Lines.Clear;
- end;
- end;
- end;
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- OpenDialog1.FileName:='';
- OpenDialog1.InitialDir:=ExtractFileDir(Application.ExeName);
- end;
- procedure TForm1.Button2Click(Sender: TObject);
- var
- TextStr:String;
- begin
- if MessageDlg('是否选择只读(Reset)模式打开该文本文件?',mtConfirmation,
- [mbYes, mbNo], 0) = mrYes then
- begin
- Memo1.ReadOnly:=True;
- Button3.Enabled:=False;
- end
- else
- begin
- Memo1.ReadOnly:=False;
- Button3.Enabled:=True;
- end;
- Reset(ATextFile);
- Memo1.Lines.Clear;
- Memo1.Lines.BeginUpdate;
- try
- While Not Eof(ATextFile) do
- begin
- ReadLn(ATextFile,TextStr);
- Memo1.Lines.Add(TextStr);
- end
- finally
- Memo1.Lines.EndUpdate;
- CloseFile(ATextFile);
- end
- end;
- procedure TForm1.Button3Click(Sender: TObject);
- var
- i:Integer;
- begin
- //AssignFile(ATextFile,Opendialog1.FileName);
- Rewrite(ATextFile);
- try
- for i:=0 to Memo1.Lines.Count-1 do
- begin
- WriteLn(ATextFile,Memo1.Lines[i])
- end;
- ShowMessage('该文件已经被成功保存到磁盘上!');
- finally
- CloseFile(ATextFile);
- end
- end;
- procedure TForm1.Button4Click(Sender: TObject);
- begin
- Close;
- end;
- end.