Link to home
Start Free TrialLog in
Avatar of rincewind666
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.
Avatar of ben-thompson
ben-thompson

I don't think there is anything like that in the component.
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.
//==============================================================================
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;

Open in new window

Avatar of rincewind666

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(Sender: TObject);
    procedure tlClick(Sender: TObject);
    procedure LoadThumbnailsBtnClick(Sender: TObject);
    procedure SaveThumbnailsBtnClick(Sender: 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.CreateThumbnailsBtnClick(Sender: TObject);
begin
 if lastDir = dlb.Directory then exit;

  lastDir := dlb.Directory;

  tl.BeginUpdate;
  try
    tl.ShowFolder(dlb.Directory+'\*.*');
  finally
    tl.EndUpdate;
  end;
end;

procedure TForm1.tlClick(Sender: TObject);
begin
  if tl.ItemIndex >= 0 then
  begin
  PathLabel.Caption := tl.Thumbnails.Items[tl.ItemIndex].FileName;
  Application.CreateForm(TPictureForm, PictureForm);
  PictureForm.Show;
  end;


end;

procedure TForm1.LoadThumbnailsBtnClick(Sender: TObject);
begin
LoadThumbsFromFile('backgrounds\xxx');
end;

procedure TForm1.SaveThumbnailsBtnClick(Sender: TObject);
begin
SaveThumbsToFile(tl,'xxx');
end;

end.
Try changing the LoadThumbnailsBtnClick procedure as below.
procedure TForm1.LoadThumbnailsBtnClick(Sender: TObject);
begin
  ReadComponentResFile('backgrounds\xxx', FN);
end;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of ben-thompson
ben-thompson

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes.  It now works perfectly.  Many thanks for your kind help  Well worth 500 points - you are brilliant!