//pas
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TForm1 = class(TForm)
Memo1: TMemo;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
begin
with OpenDialog1 do if Execute and FileExists(FileName) then
Memo1.Lines.LoadFromFile(FileName);
end;procedure TForm1.Button2Click(Sender: TObject);
var
vFileName: TFileName;
begin
with SaveDialog1 do if Execute then begin
if ExtractFileExt(FileName) = '' then
vFileName := FileName + '.txt'
else vFileName := FileName;
if FileExists(vFileName) and
(MessageDlg(Format('文件 "%s" 已经存在是否覆盖?', [vFileName]),
mtInformation, [mbYes, mbNo], 0) = mrNo) then Exit;
Memo1.Lines.SaveToFile(vFileName);
end;
end;end.//dfm
object Form1: TForm1
Left = 192
Top = 107
Width = 228
Height = 172
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Memo1: TMemo
Left = 16
Top = 8
Width = 185
Height = 89
Lines.Strings = (
'Memo1')
TabOrder = 0
end
object Button1: TButton
Left = 16
Top = 104
Width = 75
Height = 25
Caption = 'Open'
TabOrder = 1
OnClick = Button1Click
end
object Button2: TButton
Left = 128
Top = 104
Width = 75
Height = 25
Caption = 'Save'
TabOrder = 2
OnClick = Button2Click
end
object OpenDialog1: TOpenDialog
Filter = 'Text Files(*.txt)|*.txt'
Left = 96
Top = 24
end
object SaveDialog1: TSaveDialog
Filter = 'Text Files(*.txt)|*.txt'
Left = 128
Top = 24
end
end
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TForm1 = class(TForm)
Memo1: TMemo;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
begin
with OpenDialog1 do if Execute and FileExists(FileName) then
Memo1.Lines.LoadFromFile(FileName);
end;procedure TForm1.Button2Click(Sender: TObject);
var
vFileName: TFileName;
begin
with SaveDialog1 do if Execute then begin
if ExtractFileExt(FileName) = '' then
vFileName := FileName + '.txt'
else vFileName := FileName;
if FileExists(vFileName) and
(MessageDlg(Format('文件 "%s" 已经存在是否覆盖?', [vFileName]),
mtInformation, [mbYes, mbNo], 0) = mrNo) then Exit;
Memo1.Lines.SaveToFile(vFileName);
end;
end;end.//dfm
object Form1: TForm1
Left = 192
Top = 107
Width = 228
Height = 172
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Memo1: TMemo
Left = 16
Top = 8
Width = 185
Height = 89
Lines.Strings = (
'Memo1')
TabOrder = 0
end
object Button1: TButton
Left = 16
Top = 104
Width = 75
Height = 25
Caption = 'Open'
TabOrder = 1
OnClick = Button1Click
end
object Button2: TButton
Left = 128
Top = 104
Width = 75
Height = 25
Caption = 'Save'
TabOrder = 2
OnClick = Button2Click
end
object OpenDialog1: TOpenDialog
Filter = 'Text Files(*.txt)|*.txt'
Left = 96
Top = 24
end
object SaveDialog1: TSaveDialog
Filter = 'Text Files(*.txt)|*.txt'
Left = 128
Top = 24
end
end
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货