I m going slightly mad (singing Queen s song) about records with Generic Containers (TList). First, see this code:
TItemRec = record
private
FSender : TAction;
FOwnerPack : HModule;
FDockPanel : TdxDockPanel;
procedure SetDockPanel(const Value: TdxDockPanel);
procedure SetOwnerPack(const Value: HModule);
procedure SetSender(const Value: TAction);
public
property Sender: TAction read FSender write SetSender;
property OwnerPack: HModule read FOwnerPack write SetOwnerPack;
property DockPanel: TdxDockPanel read FDockPanel write SetDockPanel;
end;
TPackRec = record
private
FHandle : HModule;
var FCounter : Int16;
procedure SetCounter(const Value: Int16);
procedure SetHandle(const Value: HModule);
public
property Handle: HModule read FHandle write SetHandle;
property Counter: Int16 read FCounter write SetCounter;
procedure ChangeCounter(IncValue: Boolean = True);
end;
TRecList = class(TList<TItemRec>)
public
procedure CloseDockPanels;
end;
TPackList = class(TList<TPackRec>)
strict private
procedure DoChanges(const APack: HModule; const AAdd: Boolean = True);
public
procedure CheckForUnusedItems;
procedure AppendRef(const APack: HModule);
procedure DeleteRef(const APack: HModule);
procedure ClosePackages;
end;
TfrmMain = class(TForm)
private
FRecList : TRecList;
FPackList : TPackList;
public
end;
........................
procedure TPackList.CheckForUnusedItems;
var
i : Int16;
Flag : Boolean;
begin
repeat
Flag:= False;
if Self.Count > 0 then begin
for i:= Self.Count - 1 downto 0 do begin
Flag:= Self.Items[i].FCounter > 0;
if not Flag then begin
Self.Delete(i);
Flag:= True;
Break;
end;
Flag:= False;
end;
end;
until not Flag;
end;
procedure TPackRec.ChangeCounter(IncValue: Boolean);
var
Value : Int16;
begin
Value:= Counter;
if IncValue then
Value:= Value + 1
else
Value:= Value - 1;
Counter:= Value;
end;
I have a serious problem when trying to change value for Counter property, which is the only item with a changing value. ChangeCounter method should change value of Counter, and apparently it is done, but for CheckForUnusedItems method changed nothing, I ve tried almost everything but it seems that each of TPackList and TRecList was a constant. I show you some pics:
Items added successfully
Item of FRecList deleted
ChangeCounter method changed value of Counter
CheckForUnusedItems method doesnot see any change
Counter property keeps its value like a constant
What is happening? Is there an explanation for this? How can I resolved it? Thanks in advance.