Hello,
i have a Problem when i try to free an Object.
i have a class:
TCube = class
private
{ ----- Variables ----- }
//....
fViewModel: TBtlViewModel;
{ ----- Getter / Setter -----}
//....
public
{ ----- Properties ----- }
//....
property ViewModel: TBtlViewModel read fViewModel;
{ ----- Methods ----- }
constructor Create(cArt: TBtlType; cZLAL: TAirFlowType; cViewModel: TBtlViewModel); overload;
constructor Create(cArt: TBtlType; cZLAL: TAirFlowType); overload;
//...
created like this:
constructor TCube.Create(cArt: TBtlType; cZLAL: TAirFlowType; cViewModel: TBtlViewModel); overload;
begin
//...
fViewModel:= cViewModel;
//...
end;
constructor TCube.Create(cArt: TBtlType; cZLAL: TAirFlowType);
begin
//...
fViewModel:= TSubViewModel.Create; //TSubViewModel is a Sub class of TBtlViewModel
//...
end;
i have two cubes then wich should point to the same Viewmodel:
baseCube:= TCube.Create(3, 0);
SecCube:= TCube.Create(baseCube.Art, 1, baseCube.ViewModel);
they get removed together like this:
destructor TCube.Destroy;
begin
//...
if Assigned(fViewModel) then
fViewModel.Free;
inherited Destroy;
end;
i create Two cubes and then Destroy them, do it again, and on the third time i get Access violation. i tried using FreeAndNil, but that didn't help.
how do i check if the Viewmodel is already Freed ? or how do i Nil the References to this Object on other Objects.