Page 1 of 3

Some help with TTimer function please.

Posted: Sat Feb 06, 2010 9:32 pm
by darknessproz
This is how my program works.

There is a radiobox choice of 10 sec, 20 sec, 30 sec.

After choosing 1 and clicking the start button, the panel would start counting down from say, 10secs to 0. The problem i have now is to update the panel to reflect the countdown of the timer.

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);

if timer = 10000 then
begin
timer1.Enabled := True;
timer1.Interval := 10000;
end;

end;

procedure TForm1.RadioButton1Click(Sender: TObject);
begin
timer := 10000;
end;

procedure TForm1.RadioButton2Click(Sender: TObject);
begin
timer := 20000;
end;

procedure TForm1.RadioButton3Click(Sender: TObject);
begin
timer := 30000;
end;
some help with this?

Re: Some help with TTimer function please.

Posted: Sat Feb 06, 2010 10:47 pm
by wizme
hi, i nv work with delphi b4 but is there any method that can return the value of the timer? if can then u can spawn a new thread to run a loop to keep changing the value of the timer to a label. if there is no method on getting the return value, u can create a variable yourself and -1 every 1 sec in a loop also can.

Re: Some help with TTimer function please.

Posted: Sun Feb 07, 2010 8:08 am
by darknessproz
i'm not too sure, i'm new to delphi. perhaps i'll wait for boredness to come in.

Re: Some help with TTimer function please.

Posted: Sun Feb 07, 2010 8:13 am
by Boredness
your code is way wrong bro.

Re: Some help with TTimer function please.

Posted: Sun Feb 07, 2010 9:03 am
by darknessproz
hmm, than any suggestions on the right way? =x

Re: Some help with TTimer function please.

Posted: Sun Feb 07, 2010 10:01 am
by wizme
why do you have a if statement to start the timer, if so, if you check your 20 or 30 sec, it will not meet the if statement and will not start countdown

Re: Some help with TTimer function please.

Posted: Sun Feb 07, 2010 11:32 am
by darknessproz
its not the full code, there is also a if statement for 20sec and 30 sec. i can start the timer np, the problem now is how to display the countdown

Re: Some help with TTimer function please.

Posted: Sun Feb 07, 2010 11:46 am
by Boredness
i'm using my mac right now... i'll help you when i get back home.

Re: Some help with TTimer function please.

Posted: Sun Feb 07, 2010 12:56 pm
by darknessproz
i think i figured it out myself, but i would like to see the way you do it, as it seems my method is really inefficient. btw boredness, are there any books on delphi you can recommand?

Re: Some help with TTimer function please.

Posted: Sun Feb 07, 2010 1:19 pm
by wizme
darknessproz wrote:i think i figured it out myself, but i would like to see the way you do it, as it seems my method is really inefficient. btw boredness, are there any books on delphi you can recommand?
share your solution so ppl can learn =)

you can just remove all the if statement and just put the enable timer code in the start button

Also remember error checking, for example you only can allow the person to tick one check box