Search code examples
freepascaltfilestream

How to eliminate Free Pascal 'not recognized' compile error on TFileStream?


I am using Free Pascal 2.6.4 32-bit on Windows 8.1. I want to use a TFileStream to copy a file.

program copy;

procedure CopyFile (strFilename : string);
var
   SourceF, DestF :  TFileStream;
begin
end;
begin
   writeln('starting ');

end.

The compiler is not recognizing the TFileStream:

fpc copy_small.pas
Free Pascal Compiler version 2.6.4 [2014/03/06] for i386
Copyright (c) 1993-2014 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling copy_small.pas
copy_small.pas(5,33) Error: Identifier not found "TFileStream"
copy_small.pas(5,33) Error: Error in type definition
copy_small.pas(12) Fatal: There were 2 errors compiling module, stopping
Fatal: Compilation aborted
Error: C:\FPC\2.6.4\bin\i386-Win32\ppc386.exe returned an error exitcode (normal if you did not specify a source file to be compiled)

The sample code I found on the web using TFileStream did not have a "uses" clause. Is there something that needs to be set on the command line or included in the program in order to use a TFileStream with Free Pascal?


Solution

  • TFileStream lives in the Classes unit, so your code should be

    program copy;
    
    // To use any 'non-system' functionality add necessary units here
    uses
      Classes;
    
    procedure CopyFile (strFilename : string);
    var
       SourceF, DestF :  TFileStream;
    begin
    end;
    begin
       writeln('starting ');
    
    end.