[Solved] AV error at function TsAlphaImageList.GetCount

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #71320
    SzakiLaci
    Participant

    I’ve found a bug: Item.count was called while Items is nil!
    Here is the easy fix:

    function TsAlphaImageList.GetCount: Integer;
    {$ENDIF}
    begin
        if Items = nil then begin // when destroying the form or setting UseCache := False.  by PizzaProgram 2023-08-18
            Result := 0;
            Exit;
        end;
      Result := Items.Count;
      if (Result < ImageList_GetImageCount(Handle)) and ((Result = 0) or (Items[0].ImageFormat = ifICO)) then
        UpdateFromStd;
    end;
    • This topic was modified 1 year, 3 months ago by SzakiLaci.
    #71322
    SzakiLaci
    Participant

    Tip2:

    I had always memory release problems while destroying forms with VirtualImageList on it.
    Found a solution:
    Calling this proc when form is getting destroyed solves it:

    procedure VirtPicList_FREE(var v : TsVirtualImageList);
    begin
        if v = nil then Exit;
        try
            v.ShareImages := False;
            v.UseCache    := False; // this also calls ClearImages 
            v.Clear;
        except end;
        v := nil;
    end;

    Called simply by:

    procedure TFrm_money.FormDestroy(Sender: TObject);
    begin
      VirtPicList_FREE( MyVirtList );
      ... 
      inherited;
    end;
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.