• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 550
  • Last Modified:

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.
0
rincewind666
Asked:
rincewind666
  • 3
  • 2
1 Solution
 
ben-thompsonCommented:
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

0
 
rincewind666Author Commented:
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.
0
 
ben-thompsonCommented:
Try changing the LoadThumbnailsBtnClick procedure as below.
procedure TForm1.LoadThumbnailsBtnClick(Sender: TObject);
begin
  ReadComponentResFile('backgrounds\xxx', FN);
end;

Open in new window

0
 
ben-thompsonCommented:
Sorry, ignore last post, it contained a mistake
procedure TForm1.LoadThumbnailsBtnClick(Sender: TObject);
begin
  ReadComponentResFile('backgrounds\xxx', tl);
end;

Open in new window

0
 
rincewind666Author Commented:
Yes.  It now works perfectly.  Many thanks for your kind help  Well worth 500 points - you are brilliant!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now