?
Solved

Saving in TThumbnailList component from TMS (500 points)

Posted on 2008-11-19
5
Medium Priority
?
540 Views
Last Modified: 2012-05-05
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
Comment
Question by:rincewind666
  • 3
  • 2
5 Comments
 
LVL 2

Expert Comment

by:ben-thompson
ID: 23017629
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
 

Author Comment

by:rincewind666
ID: 23022307
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
 
LVL 2

Expert Comment

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

Open in new window

0
 
LVL 2

Accepted Solution

by:
ben-thompson earned 2000 total points
ID: 23022498
Sorry, ignore last post, it contained a mistake
procedure TForm1.LoadThumbnailsBtnClick(Sender: TObject);
begin
  ReadComponentResFile('backgrounds\xxx', tl);
end;

Open in new window

0
 

Author Comment

by:rincewind666
ID: 23022519
Yes.  It now works perfectly.  Many thanks for your kind help  Well worth 500 points - you are brilliant!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month15 days, 21 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question