Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

(delphi)how to stop a timer on countdown using a FOR-method ?

Status
Not open for further replies.

Flisk

Programmer
Oct 8, 2004
11
SE
Hello, i tried some FOR-methods . but i don’t get it to work. Just so i understand i have 2 listviews, one timer, and one button that enables the timer when the listview contains data.

It works nice, it play sound when the both listview matched each other, and it delete the values that doesn’t belong there, BUT the problem is , that i can’t make it stop in the right time.

Let’s say that i have added 10 values in the listview1, and all are lower than the topitem of listview2, then the ‘’while-process’’ deletes all 10 values, and if i put a code under that ‘if listview1.items =’0’ then timer1.enabled := false; it doesn’t work either :/

So how to stop the timer?

(don’t ask what the use of the program is ;) , right now i just playing with some stuff, for learning how it works)



procedure TForm1.Timer1Timer(Sender: TObject);
var i : integer;
begin
i := listview1.Items.count;
for i:= i downto 0 do begin
while listview1.TopItem.Caption<listview2.TopItem.Caption do listview1.TopItem.Delete;
form1.caption := inttostr(listview1.items.count);
end;
if listview2.Topitem.Caption = listview1.TopItem.Caption then
begin
PlaySound(pchar(c:\sound.wav), 0, SND_FILENAME + SND_ASYNC);
listview1.TopItem.Delete;
form1.caption := inttostr(listview1.items.count);
end;
Repeat
until form1.caption ='0';
timer1.Enabled :=false;
end;
end;
 
i always turn the timer off when I go into this routine incase the period is longer than the timer expects, so first line would be

Timer1.enabled := False;
{ Code

}
Timer1.enabled := True <== Last line of procedure


In the procedure tyou can use the word EXIT which will exit the loop.
if ##### = ##### then exit


You can also use the word ABORT to abort a procedure.

Hope this helps
 
check if xyz.count is zero delimited i.e the first value starts with zero.
If this is the case then you need to check for when value reaches 1 i.e 0 to 9 = 10 iterations when you view zero as the first iteration (first time round in the for loop)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top