Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to see TTimer interval

Posted on 2011-02-20
11
Medium Priority
?
948 Views
Last Modified: 2012-05-11
count down in TEdit?
0
Comment
Question by:pr2501
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
11 Comments
 
LVL 24

Expert Comment

by:jimyX
ID: 34936968
What do you mean by seeing the Timer interval?
If you set the timer interval to 1000 ms (1 second) then:
Edit1.Text := IntToStr(Timer1.Interval);

Open in new window


For counting down:
var  // global variable
  i:integer=20; // the number that you want to count down from
...
procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Edit1.Text := IntToStr(i);
  dec(i);
  If i = 0 then
    Timer1.Enabled := False; // to stop counting
end;

Open in new window

0
 

Author Comment

by:pr2501
ID: 34937066
If i set timer interval to 10000 ms. On timer event after 10 s specific code will be executed.

A need to know  how much time i have less until timer time will be elapsed.
0
 
LVL 24

Accepted Solution

by:
jimyX earned 1000 total points
ID: 34937248
Well you can go this way:
Set your timer interval to 1000 ms:
var  // global variable
  i:integer=10000;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Edit1.Text := IntToStr(i div 1000);
  dec(i,1000);
  If i = 0 then
    begin
      i := 10000;
      //your code that you want to execute every 10000 goes here
    end;
end;

Open in new window

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:pr2501
ID: 34938070
Ok, thank you.

Can You explain me just another thing.

Will timer event on interval interrupt another  task which was running at that moment.
And the task will continue after timer code will be executed?
0
 
LVL 24

Expert Comment

by:jimyX
ID: 34938288
>> Will timer event on interval interrupt another  task which was running at that moment.
No, whatever you have in the Timer event will run concurrently with the other code that you might have.
For example if you have ListBox, Button and Timer on a form: The Timer running as per the above code and you have pressed a button that has the following code:
procedure TForm1.Button1Click(Sender: TObject);
var
  j:integer;
begin
  for j := 1 to 30000 do
    begin
      ListBox1.Items.Add(inttostr(j));
      ListBox1.Selected[ListBox1.Items.Count-1] := true;
      Application.ProcessMessages;
    end;
end;

Open in new window

Then you get the Timer count down while the ListBox adds the loop counter.
0
 

Author Comment

by:pr2501
ID: 34938323
Thank you very much
0
 

Author Comment

by:pr2501
ID: 34938436
Try next code with two TListbox, TButon and TTimer.
They are not ruining   together?
procedure TForm4.Button1Click(Sender: TObject);
var
  j:integer;
begin
//timer1.Enabled:=false;
  for j := 1 to 30000 do
    begin
      ListBox1.Items.Add(inttostr(j));
      ListBox1.Selected[ListBox1.Items.Count-1] := true;
      Application.ProcessMessages;
    end;
end;

procedure TForm4.Timer1Timer(Sender: TObject);
var
  k:integer;
begin
  for k := 1 to 30000 do
    begin
      ListBox2.Items.Add(inttostr(k));
      ListBox2.Selected[ListBox2.Items.Count-1] := true;
      Application.ProcessMessages;
    end;
end;

Open in new window

0
 

Author Comment

by:pr2501
ID: 34938466
pleas use also in attached code below:
timer1.Enabled:=false;
procedure TForm4.Timer1Timer(Sender: TObject);
var
  k:integer;
begin
 timer1.Enabled:=false;
  for k := 1 to 30000 do
    begin
      ListBox2.Items.Add(inttostr(k));
      ListBox2.Selected[ListBox2.Items.Count-1] := true;
      Application.ProcessMessages;
    end;

end;
end.

Open in new window

0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 34939285
not really the way to go, and especially not with application.processmessages

the article i wrote about the progressbar and a thread should be a lot better than this
0
 
LVL 24

Expert Comment

by:jimyX
ID: 34966999
I should have been more clear on my answer about the concurrent processing through the Timer.
Timer can work concurrently (as i shown in my last post) but it can not work like threads. Timer can accomplish Background Processing or Multitasking but it can not perform Multithreading.
0
 

Author Comment

by:pr2501
ID: 34967693
I understand.
Now is not necsessary  for me to study Multithreading.

(But sill it would be of help if i could see how much time remains of timer time in TEdit
(like count down).)

Thank you


0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question