[fpc-pascal] class destructor not recognised

Howard Page-Clark hdpc at talktalk.net
Mon Jan 7 01:03:45 CET 2013


The following program compiles and gives output as expected, but if the 
lines that call the class destructor are uncommented it fails to compile 
with the error "identifier idents no member "Finalise"

program classConstructor;

{$mode objfpc}

uses Classes;

type

  TXClass = class
             class var int1: integer;
             class constructor Init;
             class destructor Finalise;
            end;

class constructor TXClass.Init;
begin
   int1:=-1;
end;

class destructor TXClass.Finalise;
begin
   int1:=0;
   writeln('TXClass.Finalise; int1 is ',int1);
end;

var x: TXClass;

begin
   x:= TXClass.Create;
   WriteLn('cc.int1 is ', x.int1);
//  TXClass.Finalise;
//  x.Finalise;
   x.Free;
   TXClass.int1:=1;
   WriteLn('TXClass.int1 is ', TXClass.int1);
   ReadLn;
end.

Am I not understanding how to use a class destructor, or is this a bug?

Howard



More information about the fpc-pascal mailing list