For if true

2

Well, I'm trying to run multiple downloads, one after the other, and I'd like you to just start the next one after the other is done. The codes are these:

  if StrToInt(version) < StrToInt(version2) then
  begin
    for x := StrToInt(version) to StrToInt(version2) do
      url := 'http://pokestage.ddns.net/patch/'+IntToStr(x)+'.rar';
    BaixarArquivo(IdHTTP1, url, x);
  end
  else
    sProgressBar1.Position := sProgressBar1.Max;
  slabel1.caption := '100%';
end;

Where DownloadFile returns true when the file finishes downloading. How do I just go to the next one after one is finished?

    
asked by anonymous 17.10.2014 / 18:00

1 answer

2

According to your comment:

  

Yes, it is running normally, but it already starts downloading the last file.

Your problem is at your command for . This is a syntactic Pascal syntax, Begin , and End . As { } for php among others.

So indentation is an important thing. Here's your example:

  if StrToInt(version) < StrToInt(version2) then
  begin
    // o for executa todos os contadores..
    for x := StrToInt(version) to StrToInt(version2) do
      url := 'http://pokestage.ddns.net/patch/'+IntToStr(x)+'.rar'; 

    // quando chegar aqui, a URL será a última --> valor de version2
    BaixarArquivo(IdHTTP1, url, x);
  end
  else
    sProgressBar1.Position := sProgressBar1.Max;
  slabel1.caption := '100%';
end; // <-- sobrando, a princípio

How should this for link be?

for x := StrToInt(version) to StrToInt(version2) do
begin
  url := 'http://pokestage.ddns.net/patch/'+IntToStr(x)+'.rar'; 
  BaixarArquivo(IdHTTP1, url, x);
end;

Now it generates a url and passes to the DownloadArchive method, then it generates another one, and then it goes to the DownloadArchive method. So, sucetivamente.

How lines should stay:

if StrToInt(version) < StrToInt(version2) then
begin
  for x := StrToInt(version) to StrToInt(version2) do
  begin
    url := 'http://pokestage.ddns.net/patch/'+IntToStr(x)+'.rar'; 
    BaixarArquivo(IdHTTP1, url, x);
  end;
end
else
  sProgressBar1.Position := sProgressBar1.Max;

slabel1.caption := '100%';

About the commands within the OnTimer method of the TTimer component:

There is a detail here that you need to know.

The TTimer component will run the OnTimer event from time to time as set in its Interval property. So, as desired by you in your last question, it is critical in the first line of the OnTimer method to assign the false value to the Enable method property of the TTimer component.

procedure Form1.Timer1OnTimer(sender: TObject);
begin
  Timer1.Enable := false;

  ... // restante dos seus comandos.
end;

If you do not do this, the OnTimer method will run repeatedly, trying to download again. For the given time, you can have the download commands running again before you even finished the first iteration of for with the BaixarArquivo method.

I hope this has become clear.

    
17.10.2014 / 18:12