Sign in Join

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

Mailing lists / fpc-pascal / 2003-01

Destroy Instance

4 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

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

Luis Del Aguila

I don't Understand, I compile this code with FPC 1.06 for Windows and the directive compiler -S2 -Rintel.
is it a bug?.

Thanks

Type
  TClase1 = Class
    campo1:string;
  End;
  TClase2 = Class (TClase1)
    campo2:string;
  End;
Var b:Tclase2;
Begin
  b:=TClase2.create;
  b.campo1:='hola';
  b.campo2:='hola2';
  Writeln(b.campo2);
  b.destroy;             //if destroy the instance .
  Writeln(b.campo2);     // Why the instance exist?
  Write('presione enter para terminar');readln
End.
Sebastian Günther
to Luis Del Aguila
b.destroy; //if destroy the instance . Writeln(b.campo2); // Why the instance exist?

You have to call b.Free instead of b.Destroy to properly destruct the instance.

And don't forget that the destruction will free the memory, but not override it with some initialization value; so it is possible that b.campo2 will still hold a value.

- Sebastian

Andrew J.Swan [home]
to Luis Del Aguila: I don't Understand, I compile this code with FPC 1.06 for Windows and the directive…

* Luis Del Aguila [LDA] [Tuesday, January 28, 2003] wrote:
* subject: [fpc-pascal]Destroy Instance
*

LDA> Type
LDA>   TClase1 = Class
LDA>     campo1:string;
LDA>   End;
LDA>   TClase2 = Class (TClase1)
LDA>     campo2:string;
LDA>   End;
LDA> Var b:Tclase2;
LDA> Begin
LDA>   b:=TClase2.create;
LDA>   b.campo1:='hola';
LDA>   b.campo2:='hola2';
LDA>   Writeln(b.campo2);
LDA>   b.destroy;             //if destroy the instance .
       b.Free ;
LDA>   Writeln(b.campo2);     // Why the instance exist?
LDA>   Write('presione enter para terminar');readln
LDA> End.

8o)

* Best regards ...

` _ , ' :: Linux Registered User [#168882] - (o)o) - :: The-Bat! 1.63 Beta/5 -ooO'(_)--Ooo---- :: Weakened by Windows 98/4.10.2222 A - They might or they might not, You never can tell with bees. -- [Winnie-the-Pooh] >