Библиотека программиста

25.04.2024 - Поочередно показываем рисунки

У нас ест форма, на ней Image1 и Timer1, и на диске в одной папке содержатся рисунки. Попытаемся поочередно показывать эти рисунки в image1,

Код
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
Image1: TImage;
Timer1: TTimer;
foto: TListBox;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1; i:word;

implementation

uses ShellAPI, ShlObj;// Нужны для работы с диалогом выбора
{$R *.dfm}

procedure FillBMPFileList(Folder: string; sl: TStrings);// процедура добавления файлов в список
var Rec : TSearchRec;
begin
sl.Clear;
if SysUtils.FindFirst(Folder + '*.bmp', faAnyFile, Rec) = 0 then
try
repeat
sl.Add(Folder+Rec.Name);
until SysUtils.FindNext(Rec) <> 0;
finally
SysUtils.FindClose(Rec);
end;
end;

function BrowseDialog(const Title: string; const Flag: integer): string;// вывод диалога выбора файлов
var
lpItemID : PItemIDList;
BrowseInfo : TBrowseInfo;
DisplayName : array[0..MAX_PATH] of char;
TempPath : array[0..MAX_PATH] of char;
begin
Result:='';
FillChar(BrowseInfo, sizeof(TBrowseInfo), #0);
with BrowseInfo do begin
hwndOwner := form1.Handle;
pszDisplayName := @DisplayName;
lpszTitle := PChar(Title);
ulFlags := Flag;
end;
lpItemID := SHBrowseForFolder(BrowseInfo);
if lpItemId <> nil then begin
SHGetPathFromIDList(lpItemID, TempPath);
Result := IncludeTrailingBackslash(TempPath);
GlobalFreePtr(lpItemID);
end;
end;

procedure TForm1.Button1Click(Sender: TObject);// запуск ункции вывода файлов
var fs : string;
begin
fs := BrowseDialog('Выберите папку с BMP файлами', BIF_RETURNONLYFSDIRS);
if fs = '' then Exit;
FillBMPFileList(fs, foto.Items);
timer1.Enabled:=true
end;

procedure TForm1.Timer1Timer(Sender: TObject);// вывод картинок на image
begin
if i= foto.Count-1 then exit;
image1.Picture.LoadFromFile(foto.Items.strings[i]);
inc(i);
end;

end

Опубликовано на сайте: http://www.coders-library.ru
Прямая ссылка: http://www.coders-library.ru/index.php?name=news&op=view&id=223