The following code is from
http://www.delphibasics.co.uk/RTL.asp?Name=Append&ExpandCode1=Yes#Ex1and old Delphi site.
Why does it throw an error between TextFile and text when I try and run it in Lazarus?
I know I can change text to something else but thought I'd ask the question.
I changed this {$R *.lfm} from .dfm too.
unit Unit1;
interface
uses
// The System unit does not need to be defined
Forms, Dialogs;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.lfm} // Include form definitions
procedure TForm1.FormCreate(Sender: TObject);
var
myFile : TextFile;
text : string;
begin
// Try to open the Test.txt file for writing to
AssignFile(myFile, 'Test.txt');
ReWrite(myFile);
// Write a couple of well known words to this file
WriteLn(myFile, 'Hello');
WriteLn(myFile, 'World');
// Close the file
CloseFile(myFile);
// Reopen to append a final line to the file
Append(myFile);
// Write this final line
WriteLn(myFile, 'Final line added');
// Close the file
CloseFile(myFile);
// Reopen the file for reading
Reset(myFile);
// Display the file contents
while not Eof(myFile) do
begin
ReadLn(myFile, text);
ShowMessage(text);
end;
// Close the file for the last time
CloseFile(myFile);
end;
end.