Recent

Author Topic: TextFile ~ Text naming error  (Read 2146 times)

Zath

  • Sr. Member
  • ****
  • Posts: 391
TextFile ~ Text naming error
« on: August 11, 2016, 02:02:03 pm »
The following code is from http://www.delphibasics.co.uk/RTL.asp?Name=Append&ExpandCode1=Yes#Ex1
and 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.



Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   // The System unit does not need to be defined
  7.   Forms, Dialogs;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     procedure FormCreate(Sender: TObject);
  12.   end;
  13.  
  14. var
  15.   Form1: TForm1;
  16.  
  17. implementation
  18. {$R *.lfm} // Include form definitions
  19.  
  20. procedure TForm1.FormCreate(Sender: TObject);
  21.  var
  22.    myFile : TextFile;
  23.    text   : string;
  24.  
  25.  begin
  26.   // Try to open the Test.txt file for writing to
  27.    AssignFile(myFile, 'Test.txt');
  28.    ReWrite(myFile);
  29.  
  30.   // Write a couple of well known words to this file
  31.    WriteLn(myFile, 'Hello');
  32.    WriteLn(myFile, 'World');
  33.  
  34.   // Close the file
  35.    CloseFile(myFile);
  36.  
  37.   // Reopen to append a final line to the file
  38.    Append(myFile);
  39.  
  40.   // Write this final line
  41.    WriteLn(myFile, 'Final line added');
  42.  
  43.   // Close the file
  44.    CloseFile(myFile);
  45.  
  46.   // Reopen the file for reading
  47.    Reset(myFile);
  48.  
  49.   // Display the file contents
  50.    while not Eof(myFile) do
  51.    begin
  52.      ReadLn(myFile, text);
  53.      ShowMessage(text);
  54.    end;
  55.  
  56.   // Close the file for the last time
  57.    CloseFile(myFile);
  58.  end;
  59.  
  60. end.

Cyrax

  • Hero Member
  • *****
  • Posts: 836
Re: TextFile ~ Text naming error
« Reply #1 on: August 11, 2016, 02:25:48 pm »
TForm class is descendant from TControl class which implements protected Text property. That is why you have that error.

 

TinyPortal © 2005-2018