FNC Treeview: Trouble with Images

Hello,


I have a database with about 4000 entries where small images (50x50) are sored in a blob field. i try to load it in a treeview which works quite nicely by putting them into a memorystream and loading them to ExpandedIcons from the stream with a while loop


TBlobField(FieldByName('ImageThumbnail')).SaveToStream(ms);

n := FNCTree.Nodes.Add;
n.ExpandedIcons[0, False].LoadFromStream(ms);

To speed things up I try to use the OnGetNodeIcon event by retrieving the thumbnail with a query retrieving the thumbnail (the id is stored in the datastring)

if ((AColumn = 0) and ALarge) then
  begin
    s := TMemoryStream.Create;
    Qry_1record.Params[0].AsString:= ANode.Node.DataString;
    Qry_1record.Prepare;
    Qry_1record.Open;
    if not Qry_1record.FieldByName('ImageThumbnail').IsNull then
    begin
      TBlobField(Qry_1record.FieldByName('ImageThumbnail')).SaveToStream(s);
      s.Position:= 0;
//      AIcon.LoadFromStream(s);
      ANode.Node.ExpandedIcons[AColumn, False].LoadFromStream(s);
    end;
    s.Free;
    Qry_1record.Close;
  end;


This works but after scrolling down it suddenly stops. Moving to the end of the treeview does not show anything and I get access violations.

Any help would be appreciated.

Kind regards
Gernot

Any ideas?

The OnGetNodeIcon cannot be used to load icons inside the collection item. This will potentially trigger an endless loop. Please load the icon outside of the loop in the collection item, or return a reference to the icon inside the OnGetNodeIcon.