View Single Post
  #5  
Old 07-20-2004, 05:39 AM
MrBaseball34 MrBaseball34 is offline
Senior Member
 
Join Date: Jan 2001
Posts: 7,260
Default RE: Save/Load TImageList to/from a file ...

Found this on the Borland newsgroups, give it a try...

The following code fragments (D5) save/load ImageLists
to/from stream or file:

[pre]
Uses
CommCtrl;

{...}

Procedure SaveImageListToStream(IL:TImageList;AStream:TStrea m);
Var SAdapter:TStreamAdapter;
Begin
SAdapter:=TStreamAdapter.Create(AStream);
Try
If Not ImageList_Write(IL.Handle,SAdapter) Then Begin
{ error handling ... }
End;
Finally
SAdapter.Free;
End;
End;

Procedure LoadImageListFromStream(IL:TImageList;AStream:TStr eam);
Var SAdapter:TStreamAdapter;
Begin
SAdapter:=TStreamAdapter.Create(AStream);
Try
IL.Handle:=ImageList_Read(SAdapter);
If (IL.Handle=0) Then Begin
{ error handling ... }
End;
Finally
SAdapter.Free;
End;
End;

Procedure SaveImageListToFile(IL:TImageList;Filename:String) ;
Var AStream:TFileStream;
Begin
AStream:=TFileStream.Create(Filename,fmCreate);
Try
SaveImageListToStream(IL,AStream);
Finally
AStream.Free;
End;
End;

Procedure LoadImageListFromFile(IL:TImageList;Filename:Strin g);
Var AStream:TFileStream;
Begin
AStream:=TFileStream.Create(Filename,fmOpenRead);
Try
LoadImageListFromStream(IL,AStream);
Finally
AStream.Free;
End;
End;
[/pre]

MB34
Reply With Quote