A.2 reading ppufiles

We will first create an object ppufile which will be used below. We are opening unit test.ppu as an example.

uses ppu;  
 
{$mode objfpc}  
 
var  
  ppufile : tppufile;  
begin  
{ Initialize object }  
  ppufile:=tppufile.create('test.ppu');  
{ open the unit and read the header, returns false when it fails }  
  if not ppufile.openfile then  
    Writeln('error opening unit test.ppu');  
 
{ here we can read the unit }  
 
{ close unit }  
  ppufile.closefile;  
{ release object }  
  ppufile.free;  
end.

Note: When a function fails (for example not enough bytes left in an entry) it sets the ppufile.error variable.