Illegal Loop + Expression in Valuator

Asked

Viewed 60 times

0

I am downloading several files (one after the other) by one loop, but as soon as the first one goes down, it gives crash. Follows the loop:

  for x := StrToInt(version)+1 to StrToInt(version2) do
  begin
    url := baseurl+'/'+IntToStr(x)+'.7z';
    BaixarArquivo(IdHTTP1, url, x);
    if pexit = true then break;
  end;

On the line if pexit = true then break; when I put the mouse on top, gives the message:

Break = Illegal expression in Evaluator.

How can I avoid that mistake?

Edit: I found that the error is within the Download function. That line:

downloadedf[high(downloadedf)+1] := IntToStr(Name) + ExtractFileExt(Url);

Where

IntToStr(Name) tem o valor de '1'. (String)
ExtractFileExt(Url) tem o valor de '.7z'. (String)

And I had already declared:

downloadedf : array of string;

And over the line of error:

SetLength(downloadedf, Length(downloadedf) +1);

There’s something wrong?

  • What is the value of the variable pexit? If it really is boolean type do not check this way. if pexit = true is the same thing as if pexit. Now, if expecting a true or a false, always. If pexit is worth one of these values, just use the variable, do not need to ask if it is worth it, use the existing value. But the error may be precisely because the variable may be worth something else.

  • @bigown, Any time "pexit" assumes another value that is not true or false, and test: if pexit then break end; and continues the problem.

  • Unless there’s something else that doesn’t appear in the code, then it’s impossible to give that error where you’re pointing.

  • I found the error line is inside the Download function, I will edit the post.

2 answers

1

The mistake was in:

downloadedf[high(downloadedf)+1]

I was already increasing the length before and tried to insert a value into a non-existent field. I just took the +1.

1


Imagine that, so you declare the array:

downloadedf : array of string;

And then at that point, your array has Length 0 (Length(downloadedf) = 0)

The function Length() is used to get the size, in a empty array is 0 and then it’s life-size.

The function Low() is used to get the lowest index of an array, if it is empty is -1, otherwise it returns the lowest index which is usually 0

The function High() is used to get the highest index of an array, if it is empty is -1, otherwise it returns the highest index, which usually equates to Length() - 1

So, after increasing the size of the array with the SetLength, the High will already return you the last index of the array in question

Browser other questions tagged

You are not signed in. Login or sign up in order to post.