The example below shows how to save the contents of two Edit-components to a text file C:\Test\Data.txt
procedure TForm1.btnWriteClick(Sender: TObject); Reading strings from a text file is very similar, but in order to be on the safe side, you need an extra step. Before trying to read, you have to check if the file exists. You also need an extra variable to receive the strings that you read from the file. This are the steps:
Here's an example that loads the contents of the two Edits from the text file C:\Test\Data.txt procedure TForm1.btnReadClick(Sender: TObject);
var
F: TextFile;
S: string;
begin
if FileExists('C:\Test\Data.txt') then begin
AssignFile(F, 'C:\Test\Data.txt');
Reset(F);
ReadLn(F, S);
Edit1.Text := S;
ReadLn(F, S);
Edit2.Text := S;
CloseFile(F);
end
else
ShowMessage('File C:\Test\Data.txt not found');
end;
|
|
| Crash Course Delphi | Become member of the DelphiLand Club and get our Crash Course Delphi, plus the fully commented source code of numerous projects, plus guaranteed answers from our Q/A Forum. Membership is for life! |
TOP DelphiLand
Club Membership DC Library Forum Forum
Archives
Crash Course Delphi TURBO
Delphi Explorer FAQ Tips Source
Code Downloads Links
© Copyright 1999-2006
Studiebureau Festraets