如何将form中Edit.Text保存为文件!(100分)

H

hcbride

Unregistered / Unconfirmed
GUEST, unregistred user!
如何将form中Edit.Text保存为文件!
保存后如何读取文件中的内容!
谢谢您的帮助!
 
你可以保存为INI文件, 具体操作如下:
uses
inifiles;

with TIniFile.Create('C:/Test.Ini') do
try
WriteString('Test', 'Edit1', Edit1.Text); //写
Edit1.Text := ReadString('Test', 'Edit1', ''); //读
finally
Free;
end;
 
同意 xianjun
 
写了后为什么要读
 
procedure TForm1.FormCreate(Sender: TObject);
var
I: Integer;
begin
with TIniFile.Create(cFileNameIni) do try
for I := 0 to ComponentCount - 1 do
if Components is TEdit then
TEdit(Components).Text := ReadString('Edit', Components.Name, '');
finally
Free;
end;
end;

procedure TForm1.FormDestroy(Sender: TObject);
var
I: Integer;
begin
with TIniFile.Create(cFileNameIni) do try
for I := 0 to ComponentCount - 1 do
if Components is TEdit then
WriteString('Edit', Components.Name, TEdit(Components).Text);
finally
Free;
end;
end;
 
保存用SaveDialog即可
var
Ftext:TextFile;
s:string;
begin
if SaveDialog1.Execute then
AssignFile(Ftext,SaveDialog1.FileName);
s:=Edit1.Text;
rewrite(Ftext);
Write(Ftext,s);
CloseFile(Ftext);
end;
读取文件中的内容用OpenDialog即可
var
Ftext:TextFile;
s:string;
begin
if OpenDialog1.Execute then
AssignFile(Ftext,OpenDialog1.FileName);
Reset(Ftext);
Read(Ftext,s);
Edit1.Text:=s;
CloseFile(Ftext);
end;
 
谢谢大家的帮忙,我试试看!
我要完成的任务是:将参数(文件路径&扫描文件的间隔时间)由用户设置!然后取出设置,
去扫描指定路径指定文件。读出文件内容,将相应内容作为email发送!
:)
 
一个简单的问题,到是可以考考富翁们的水平,不错,这么多方法。
 
多人接受答案了。
 
顶部