[lazarus] Order of destruction in TCustomListBox

Micha Nelissen micha at neli.hopto.org
Sun Dec 14 08:57:14 EST 2003


Mattias Gaertner wrote:

> On Sat, 13 Dec 2003 22:22:30 +0100  Micha Nelissen <micha at neli.hopto.org>
> wrote:
> 
> 
>>Mattias Gaertner wrote:
>>
>>
>>>On Sat, 13 Dec 2003 19:39:39 +0100  Micha Nelissen
>>><micha at neli.hopto.org> wrote:
>>>
>>>
>>>>Aah, the 'yucky'-ness of Object Pascal :-(.
>>>
>>>
>>>What do you mean?
>>
>>I don't like the fact of pascal that it's possible that overriden 
>>functions get called although their constructor hasn't run or their 
>>destructor has run.
> 
> 
> What function gets called after the destructor has run?

We need some code :-).

<code>
program Virt;

{$mode objfpc}
{$h+}

type
CA = class
private
   procedure SomeFunc; virtual; abstract;
public
   constructor Create;
end;

CB = class(CA)
private
   procedure SomeFunc; override;
public
   constructor Create;
end;

constructor CA.Create;
begin
   SomeFunc;
end;

constructor CB.Create;
begin
   inherited;
   writeln('Constructor');
end;

procedure CB.SomeFunc;
begin
   writeln('CB.SomeFunc call');
end;

var
   VB: CB;
begin
   VB := CB.Create;
   VB.Free;
end.
</code>

<output>
CB.SomeFunc call
Constructor
</output>

Which is not logical, IMHO.

Regards,

Micha.






More information about the Lazarus mailing list