Chris Cauchi
You do not need to know the number of objects in advance when using a
TList - that's kind of the idea of a TList and its "Count" property.. Here
are quick instructions for using TList (untested..):
var
List: TList;
p: ^TBitmap; // pointer to the type of object
x: integer;
begin
// create the list
List := TList.Create;
// allocate memory for the pointer
New(p);
// assign the pointer
p^ := Image1.Picture.Bitmap;
// add to List
List.Add(p);
// use the list
Canvas.Draw(0,0,TBitmap(List[0]^));
// free the memory
for x := 0 to List.Count - 1 do
Dispose(List[x]);
List.Free;
end;
--
David Reed
Diamond Software Group, Inc
www.diamondsg.com
var
bs: TBlobStream;
list: TList;
pBM: ^TBitmap;
i: integer;
begin
list:=TList.Create;
ITable.First;
for i:=0 to ITable.RecordCount-1
do begin
bs:=TBlobStream.Create(ITableBitmap,bmRead);
New(pBM);
pBM^:=TBitmap.Create;
pBM^.LoadFromStream(bs);
list.Add(pBM^);
bs.Free;
ITable.Next;
end;
And, to free the objects, do I call TBitmap(list.Items[x]).Free, or
Dispose(list.Items[x])?
Thanks again
Chris Cauchi
> And, to free the objects, do I call TBitmap(list.Items[x]).Free, or
> Dispose(list.Items[x])?
You have to destroy both the bitmap object *and* the pointer var. When
freeing the bitmap, dereference the pointer object using the following:
TBitmap(list.Items[x]^).Free
You were correct with the syntax for dispose, tho.. put the call in a loop
"for x := 0 to List.Count - 1", preferably in a try...finally loop as well.
Keep practicing with pointers until you completely understand their role and
how they work - they are invaluable to a windows programmer, and it'll help
many more concepts in Delphi make sense..
formatCodeBitmapsSL:=TStringList.Create;
for i:=0 to dm.FormatAllQBE.RecordCount-1
do begin
if not dm.FormatAllQBECode.IsNull
then begin
New(pBm);
pBm^:=TBitmap.Create;
pBm^.Assign(dm.FormatAllQBEGraphic);
formatCodeBitmapsSL.AddObject(dm.FormatAllQBECode.Value,pBm^);
Dispose(pBm);
end;
dm.FormatAllQBE.Next;
end;
Then to free the whole shebang, I simply need this, true?...
for i:=0 to formatCodeBitmapsSL.Count-1
do TBitmap(formatCodeBitmapsSL.Objects[i]).Free;
formatCodeBitmapsSL.Free;
Chris Cauchi