rincewind666
asked on
Saving in TThumbnailList component from TMS (500 points)
I have a component called ThumbnailList from TMS which displayed all pictures in a folder as thumbnails. It takes a while to display every time so I would like to dot his once only and then save into a file. How can I do this?
I am using Delphi6. I am giving the maximum 500 points for this. Many thanks for your help.
I am using Delphi6. I am giving the maximum 500 points for this. Many thanks for your help.
ASKER
I am getting the following error when I try to load it again (however something is being saved):
class TThumbnailList not found
Sorry. I'm a beginner in Delphi. I am using the following code:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ThumbnailList, SkinBoxCtrls, spfilectrl, SkinCtrls,
SkinData, DynamicSkinForm, AdvPicture;
type
TForm1 = class(TForm)
spDynamicSkinForm1: TspDynamicSkinForm;
spSkinData1: TspSkinData;
PathLabel: TspSkinLabel;
spSkinPanel1: TspSkinPanel;
DriveComboBox1: TspSkinDriveComboBox;
dlb: TspSkinDirectoryListBox;
CreateThumbnailsBtn: TspSkinButton;
Cooler: TspCompressedStoredSkin;
tl: TThumbnailList;
LoadThumbnailsBtn: TspSkinButton;
SaveThumbnailsBtn: TspSkinButton;
procedure CreateThumbnailsBtnClick(S ender: TObject);
procedure tlClick(Sender: TObject);
procedure LoadThumbnailsBtnClick(Sen der: TObject);
procedure SaveThumbnailsBtnClick(Sen der: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
lastDir: string;
implementation
uses Unit2;
{$R *.dfm}
//======================== ========== ========== ========== ========== ========== ====
procedure SaveThumbsToFile(Thumbs : TThumbnailList; const FN : string);
begin
WriteComponentResFile(FN, Thumbs);
end;
//======================== ========== ========== ========== ========== ========== ====
function LoadThumbsFromFile(const FN : string) : TThumbnailList;
begin
Result := ReadComponentResFile(FN, nil) as TThumbnailList;
end;
procedure TForm1.CreateThumbnailsBtn Click(Send er: TObject);
begin
if lastDir = dlb.Directory then exit;
lastDir := dlb.Directory;
tl.BeginUpdate;
try
tl.ShowFolder(dlb.Director y+'\*.*');
finally
tl.EndUpdate;
end;
end;
procedure TForm1.tlClick(Sender: TObject);
begin
if tl.ItemIndex >= 0 then
begin
PathLabel.Caption := tl.Thumbnails.Items[tl.Ite mIndex].Fi leName;
Application.CreateForm(TPi ctureForm, PictureForm);
PictureForm.Show;
end;
end;
procedure TForm1.LoadThumbnailsBtnCl ick(Sender : TObject);
begin
LoadThumbsFromFile('backgr ounds\xxx' );
end;
procedure TForm1.SaveThumbnailsBtnCl ick(Sender : TObject);
begin
SaveThumbsToFile(tl,'xxx') ;
end;
end.
class TThumbnailList not found
Sorry. I'm a beginner in Delphi. I am using the following code:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ThumbnailList, SkinBoxCtrls, spfilectrl, SkinCtrls,
SkinData, DynamicSkinForm, AdvPicture;
type
TForm1 = class(TForm)
spDynamicSkinForm1: TspDynamicSkinForm;
spSkinData1: TspSkinData;
PathLabel: TspSkinLabel;
spSkinPanel1: TspSkinPanel;
DriveComboBox1: TspSkinDriveComboBox;
dlb: TspSkinDirectoryListBox;
CreateThumbnailsBtn: TspSkinButton;
Cooler: TspCompressedStoredSkin;
tl: TThumbnailList;
LoadThumbnailsBtn: TspSkinButton;
SaveThumbnailsBtn: TspSkinButton;
procedure CreateThumbnailsBtnClick(S
procedure tlClick(Sender: TObject);
procedure LoadThumbnailsBtnClick(Sen
procedure SaveThumbnailsBtnClick(Sen
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
lastDir: string;
implementation
uses Unit2;
{$R *.dfm}
//========================
procedure SaveThumbsToFile(Thumbs : TThumbnailList; const FN : string);
begin
WriteComponentResFile(FN, Thumbs);
end;
//========================
function LoadThumbsFromFile(const FN : string) : TThumbnailList;
begin
Result := ReadComponentResFile(FN, nil) as TThumbnailList;
end;
procedure TForm1.CreateThumbnailsBtn
begin
if lastDir = dlb.Directory then exit;
lastDir := dlb.Directory;
tl.BeginUpdate;
try
tl.ShowFolder(dlb.Director
finally
tl.EndUpdate;
end;
end;
procedure TForm1.tlClick(Sender: TObject);
begin
if tl.ItemIndex >= 0 then
begin
PathLabel.Caption := tl.Thumbnails.Items[tl.Ite
Application.CreateForm(TPi
PictureForm.Show;
end;
end;
procedure TForm1.LoadThumbnailsBtnCl
begin
LoadThumbsFromFile('backgr
end;
procedure TForm1.SaveThumbnailsBtnCl
begin
SaveThumbsToFile(tl,'xxx')
end;
end.
Try changing the LoadThumbnailsBtnClick procedure as below.
procedure TForm1.LoadThumbnailsBtnClick(Sender: TObject);
begin
ReadComponentResFile('backgrounds\xxx', FN);
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes. It now works perfectly. Many thanks for your kind help Well worth 500 points - you are brilliant!
Either you could write the thumbnails to file, like XP does with thumbs.db or try ReadComponentResFile and WriteComponentResFile. This will save all of the component's properties, including the pictures and their paths to a res file, though I've never done it.
Open in new window