unit decMainFormUnit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    OpenDialog1: TOpenDialog;
    Edit1: TEdit;
    ListBox1: TListBox;
    Image1: TImage;
    procedure Button1Click(Sender: TObject);
    procedure ListBox1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses decThumbsDB;

procedure TForm1.Button1Click(Sender: TObject);
var SR: TdecTDB_SearchRec;
begin
  if OpenDialog1.Execute then
    begin
      Edit1.Text := OpenDialog1.FileName;
      ListBox1.Clear;
      Image1.Picture.Assign(nil);
      if decTDB_FindFirst(Edit1.Text, SR) = 0 then
        try
          repeat
            ListBox1.Items.Add(SR.FFindData.FFileName);
          until decTDB_FindNext(SR) <> 0;
        finally
          decTDB_FindClose(SR);
        end;
    end;
end;

procedure TForm1.ListBox1Click(Sender: TObject);
var SR: TdecTDB_SearchRec;
    G: TGraphic;
    FN: string;
begin
  Image1.Picture.Assign(nil);
  if decTDB_FindFirst(Edit1.Text, SR) = 0 then
    try
      repeat
        FN := SR.FFindData.FFileName;
        if AnsiCompareFileName(ListBox1.Items[ListBox1.ItemIndex], FN) = 0 then
          begin
            G := decTDB_ExtractThumbnail(SR);
            if G <> nil then
              try
                Image1.Picture.Assign(G);
              finally
                G.Free;  //!!!
              end;
            break;
          end;
      until decTDB_FindNext(SR) <> 0;
    finally
      decTDB_FindClose(SR);
    end;
end;

end.
