The following code works just fine, but it shouldn't ! When I click the Button1, the object is destroyed first, and then its Value is used and I don't receive any Access Violation or something... Even more, the multiply operation gives the correct result, that proves that Obj1 is not destroyed ! But then again, this is not true either, because when I close the program it does'n report any memory leakage. I'm very confused.
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type MyObj = class(TObject) Value: Cardinal; end; TForm1 = class(TForm) Button1: TButton; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); public Obj1:MyObj; end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); begin Obj1.Free; Obj1.Value:=Obj1.Value * 5; Caption:=IntToStr(Obj1.Value); end; procedure TForm1.FormCreate(Sender: TObject); begin ReportMemoryLeaksOnShutdown:=true; Obj1:=MyObj.Create; Obj1.Value:=10; end; end.