title: Records and Generic Containers in Delphi
body: <p>I'm going slightly mad (singing Queen's song) about records with Generic Containers (TList). First, see this code:</p>
  
  <pre><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&lt;TItemRec&gt;)
    public
      procedure CloseDockPanels;
    end;
  
    TPackList = class(TList&lt;TPackRec&gt;)
    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 &gt; 0 then begin
        for i:= Self.Count - 1 downto 0 do begin
          Flag:= Self.Items[i].FCounter &gt; 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;
  </code></pre>
  
  <p>I have a serious problem when trying to change value for <strong>Counter</strong> 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:</p>
  
  <p>Items added successfully</p>
  
  <p><img src="https://ifynmg.blu.livefilestore.com/y1p6OgI5SSaLdak-EtY4shX76pR1f2ZiIASipNeJ7yRPn0hbOTB7U3CKG_VDkvjaf37RcOzB7jJuJnJDpW6YLjb2UpzUor5eKZc/01.jpg" alt="Pic01"></p>
  
  <p>Item of FRecList deleted</p>
  
  <p><img src="https://ifynmg.blu.livefilestore.com/y1p6OgI5SSaLdbsOS_KrseMdlSJO2f5N5flC5N0BE9u5DhbFMLKLLS5lhezPHM45pLC_QWb08DJPKhOEnepjY2s8LW8ZguCtYEr/02.jpg" alt="Pic02"></p>
  
  <p>ChangeCounter method changed value of Counter</p>
  
  <p><img src="https://ifynmg.blu.livefilestore.com/y1pmccN61pEmDBFrq764d-bed8_yjLagLw_NCm4vAZY0IKYql8HTgIgmF-1-OWVDN9T7BvQI6xTtVhmUzxTD_cUscufQ8R0Fvrm/03.jpg" alt="Pic03"></p>
  
  <p>CheckForUnusedItems method doesnot see any change</p>
  
  <p><img src="https://ifynmg.blu.livefilestore.com/y1pYBYDjfimmKvkFMYBwmsUingpRuFOAV6LSZrp26uNKeFOfdgrbHI7gPN8FVYFUEPGM74ki4Xph8aZOSeQqFrHCVN1iDyJwFbh/04.jpg" alt="Pic04"></p>
  
  <p>Counter property keeps its value like a constant</p>
  
  <p><img src="https://public.blu.livefilestore.com/y1pkKTtcSP2c2gg8DCKjPoeMjrS_cFEIQM9m7Rq7ZsPICHZR8R0QMcG4RVUsdqVlIfUZVidXcCTK2o4fREXVZghYQ/05.jpg" alt="Pic05"></p>
  
  <p>What is happening? Is there an explanation for this? How can I resolved it?
  Thanks in advance.</p>