index of Bounds and timer problems

Asked

Viewed 77 times

-1

Next, I have a timer that fills 2 fields in a webbrowser, the same makes the following function...

var 
  pega : string; 
begin 
  pega := Listaimportados.Items[i]; 
  I := i +1 
  nome.text := Copy(pega, 0, 10); 
  Webbrowser1.OleObject.Document.all.Item('login', 0).value := nome.text;

in this it goes repeating the action every 4 seconds, as you can see the i+1 jumps to the next line, which in this case is imported in imported lists(listbox).

however I have a problem, if I insert less than one item in the listbox(imported lists) it starts giving error, list of Bounds, how to solve?

  • What was I supposed to do when the last line came?

  • 1

    Stop timer in timer1.enabled case := false;

1 answer

1


You said in the comments that when it came to the end, you should stop the timer.
In that case it’s simple:

var 
  pega : string; 
begin 
  if I = Listaimportados.Count then
  begin
    timer1.Enabled:= False;
    Exit;
  end;
  pega := Listaimportados.Items[i]; 
  I := i +1 
  nome.text := Copy(pega, 0, 10); 
  Webbrowser1.OleObject.Document.all.Item('login', 0).value := nome.text;

In this code, I am assuming that Imported Listings is an instance of a class TStringList

Browser other questions tagged

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