I am new to interfaces and am trying to use them in my latest project. I have this (simplified) interface:
IBoardShape = interface(IInterface)
function GetColor: integer;
procedure SetColor(const aColor: integer);
property Color: integer read GetColor write SetColor;
end;
Several classes leave it like this:
TGameRectangle = class(TRectangle, IBoardShape)
private
FColor: integer;
function GetColor: integer;
procedure SetColor(const aColor: integer);
property Color: integer read GetColor write SetColor;
end;
I have a factory for creating shapes in my own data module.
function TdmShapeManager.CreateRect(aParent: TLayout): IBoardShape;
var
lRect: TGameRectangle;
begin
lRect := TGameRectangle.Create(self);
lRect.Parent := aParent;
lRect.Align := TAlignLayout.alClient;
result := lRect as IBoardShape;
end;
The result is added to TList<IBoardShape>.
All this worked until I started deleting the shapes at runtime. I found that the TList[I] := nilitem does not release, the control will simply remain on the screen. So from here I'm not sure. I found that I can transfer the object to TShape and make a call. Free, but it doesn’t sound like that. (I tried and it works, but then it leads to other problems - errors inside Delphi code when trying to free the interface.)
, : TGameRectangle TInterfacedObject, ? , TInterfacedObject?