index of bounds and problems with timer

-1

Next, I have a timer that fills 2 fields in a webbrowser, it does 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 he repeats the action every 4 seconds, as you can see i + 1 jumps to the next line, which in case it is imported into listboxes (listbox).

But I have a problem, if I enter less than one item in the listbox, it starts to give error, list of bounds, how to solve?

    
asked by anonymous 31.03.2015 / 09:34

1 answer

1

You said in the comments that when it came to the end, you should stop the timer. Home In this 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'm assuming that ListItems is an instance of a class TStringList

    
31.03.2015 / 20:57