For proceed if true

Well, I'm trying to run multiple downloads, one after the other, and I'd like it to only start the next one after the other finishes. 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 to Downloadfile returns true when the file finishes downloading. How do I make it only go to the next one after one is completed?

Author: Gabriel Sales, 2014-10-17

1 answers

According to your comment:

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

Your problem is in your for command.
It is a matter of syntax of the language Pascal , the Begin and the End.
Like the { } for php among others.

So the identity be an important thing.
See his 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

What should this loop look like for?

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 one url and passes to the download method, then it will generate another, and then passes to the download method. So succesfully.

How the rows should look:

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 commands within the OnTimer method of the TTimer component:

There is a detail here that you need to know.

The TTimer component will execute the OnTimer event from time to time as set in its own property Interval.
So, as you wanted in your last question, it is critical in the first line of the OnTimer method to assign the value false 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 do the download commands again.
For the informed time, you may have the download commands running again before you have even finished the first iteration of for with method BaixarArquivo.

I hope that has become clear.

 2
Author: Comunidade, 2020-06-11 14:45:34