How to read text files in delphi
var
Form1: TForm1;
implementation
{$R *.dfm} // Include form definitions
procedure TForm1.FormCreate(Sender: TObject);
var
fileName : string;
myFile : TextFile;
data : string;
begin
// Try to open a text file for writing to
fileName := 'Test.txt';
AssignFile(myFile, fileName);
ReWrite(myFile);
// Write to the file
Write(myFile, 'Hello World');
// Close the file
CloseFile(myFile);
// Reopen the file in read mode
Reset(myFile);
// Display the file contents
while not Eof(myFile) do
begin
ReadLn(myFile, data);
ShowMessage(data);
end;
// Close the file for the last time
CloseFile(myFile);
// Now see if the file exists
if fileexists(fileName)
then ShowMessage(fileName+' exists OK')
else ShowMessage(fileName+' does not exist');
// Delete the file and look again
DeleteFile(fileName);
if fileexists(fileName)
then ShowMessage(fileName+' still exists!')
else ShowMessage(fileName+' no longer exists');
end;
end.
Are there any code examples left?
New code examples in category Delphi
-
Delphi 2022-03-27 19:40:03 delphi keydown enter
-
Delphi 2022-03-20 03:25:01 get time in milliseconds delphi
-
Delphi 2022-03-16 18:50:01 delphi random letter
-
Delphi 2022-02-14 03:45:08 remove unnecessary packages raspi pixel
-
Delphi 2022-02-02 21:15:46 delete in delphi
-
Delphi 2022-02-02 17:26:35 INSERT into syntax error in delphi
-
Delphi 2022-01-23 12:15:39 pyhton instagram bot
-
Delphi 2022-01-23 09:05:59 delphi calculator
-
Delphi 2021-11-21 18:31:10 download jupyter for linux
-
Delphi 2021-11-20 04:57:08 copy delphi