1

I'm a noob in Delphi V7. I'm creating a SlideShow, i need the images loaded in a ListView be sent to a Picture object using the OnTimer event of the Timer object. See the code I'm using:

    procedure TForm1.Button1Click(Sender: TObject);
var i : integer;
begin
if open1.execute then
begin
 for i := 0 to Open1.Files.Count - 1 do

   //     ShowMessage(Open1.Files[i]);   // processa os arquivos aqui
with add.Items.Add do
  begin
    Caption:=ExtractFileName(Open1.Files[i]);
    SubItems.Add( Open1.Files[i]);
    SubItems.Add(ExtractfileExt(Open1.files[i]));

  end;

The above section add various images of a opendialog object into a ListView.

procedure TForm1.Button2Click(Sender: TObject);
begin
timer1.enabled:=true;
//image1.Picture.loadfromfile(add.Items.Item[0].Caption);//Assign(add.Items.Item[0].Caption);
end;

This active the timer.

procedure TForm1.Timer1Timer(Sender: TObject);
var i: integer;

begin

for i := 0 to add.items.count -1 do
begin
image1.Picture.loadfromfile(add.Items.Item[i].Caption  );//Assign(add.Items.Item[0].Caption);
  end;
end;

But i'm need help in the last code. This not working.

I want the images to be loaded one by one in the image1 object whenever the timer times out, giving a slideshow effect, but the code that I typed in the OnTimer event, carries only one image.

4

1 回答 1

0

在您的计时器中,您加载每个图像,用下一个图像覆盖每个图像,直到循环终止。此时图像Count-1仍然存在。

您需要跟踪在每次执行计时器事件之间持续存在的某些状态。TForm1在名为FLatestImageIndextype的字段中声明一个字段Integer。然后让你的计时器像这样:

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  FLatestImageIndex := FLatestImageIndex mod add.Items.Count;//wrap around
  image1.Picture.LoadFromFile(add.Items.Item[FLatestImageIndex].Caption);
  inc(FLatestImageIndex);
end;

如果您有停止和启动幻灯片的代码,那么您可能希望在FLatestImageIndex每次启动时重新初始化。

于 2013-05-20T18:00:55.463 回答