
18.06.2009, 15:56
|
Новичок
|
|
Регистрация: 01.06.2009
Сообщения: 54
Репутация: 27
|
|
ImageViewer
Пишу прогу ImageViever, но не получается осуществить переход между изображениями с помощью SpeedButton'ов! Помогите, пожалуйста, разобраться, что не так с моим кодом!
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, Buttons, ExtDlgs;
type
TForm1 = class(TForm)
Panel1: TPanel;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
Image1: TImage;
OpenPictureDialog1: TOpenPictureDialog;
SavePictureDialog1: TSavePictureDialog;
procedure FormCreate(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton3Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
aPath: string; // каталог, который выбрал пользователь
aSearchRec : TSearchRec; // информация о файле
Pictures : TStringList; // список иллюстраций
n: integer; // номер иллюстрации, отображаемой в данный момент
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
Pictures := TStringList.Create;
SpeedButton2.Enabled := False;
SpeedButton3.Enabled := False;
with OpenPictureDialog1 do
begin
Options := Options + [ofPathMustExist, ofFileMustExist];
InitialDir := ExtractFilePath(Application.ExeName);
end;
with SavePictureDialog1 do
begin
InitialDir := ExtractFilePath(Application.ExeName);
end;
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
if OpenPictureDialog1.Execute then
begin
Form1.Caption := OpenPictureDialog1.FileName;
Image1.Picture.LoadFromFile(OpenPictureDialog1.FileName);
end;
if Pictures.Count > 1 then
SpeedButton3.Enabled := True;
// отобразить иллюстрацию
n := 0; // номер отображаемой иллюстрации
try
Form1.Image1.Picture.LoadFromFile(aPath + Pictures[n]);
except on EInvalidGraphic do Form1.Image1.Picture.Graphic := nil;
end;
if Pictures.Count = 1 then
SpeedButton3.Enabled := False;
end;
procedure TForm1.SpeedButton3Click(Sender: TObject);
begin
// вывести картинку
n := n+1;
try
Form1.Image1.Picture.LoadFromFile(aPath + Pictures[n]);
except on EInvalidGraphic do Form1.Image1.Picture.Graphic := nil;
end;
if n = Pictures.Count-1 then
SpeedButton2.Enabled := False;
// если кнопка "Предыдущая" не доступна,
// сделать ее доступной
if (n > 0 ) and SpeedButton3.Enabled = False then
SpeedButton3.Enabled := True;
end;
procedure TForm1.SpeedButton2Click(Sender: TObject);
begin
// вывести картинку
n := n-1;
try
Form1.Image1.Picture.LoadFromFile(aPath + Pictures[n]);
except on EInvalidGraphic do Form1.Image1.Picture.Graphic := nil;
end;
if n = 0 then
SpeedButton3.Enabled := False;
// если кнопка "Следующая" не доступна,
// сделать ее доступной
if (n < Pictures.Count) and SpeedButton2.Enabled = False then
SpeedButton2.Enabled := True;
end;
end.
|