Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2013-01

class destructor not recognised

5 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Howard Page-Clark

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

Reply by email

Paul Ishenin
to Howard Page-Clark

07.01.13, 8:03, Howard Page-Clark пишет:

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"

...

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

You don't understand.

Class destructor is called automatically like finalization section of a unit. You can't call it directly.

Best regards,
Paul Ishenin

Reply by email

Jorge Aldo G. de F. Junior
to Paul Ishenin

Are you SURE you need "class constructor" ?

because usually all you need is a plain old constructor... like

constructor create(const aparam : integer); // etc

to be honest i never used a class constructor before... (dont even know this exists).

2013/1/6 Paul Ishenin :

Show quoted text 22 lines
07.01.13, 8:03, Howard Page-Clark пишет: > 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" ... > Am I not understanding how to use a class destructor, or is this a bug? You don't understand. Class destructor is called automatically like finalization section of a unit. You can't call it directly. Best regards, Paul Ishenin _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Howard Page-Clark
to Paul Ishenin: 07.01.13, 8:03, Howard Page-Clark пишет: ... You don't understand. Class destructor…
Paul Ishenin wrote
You don't understand. Class destructor is called automatically like finalization section of a unit. You can't call it directly.

Thanks for the clarification. I was confused by the fact that the writeln called in the class destructor is not displayed. But I guess it is executed so late in the process that it cannot be seen?

Howard

Reply by email