Delphi Timer with Pertol Pump (easy) Help needed

Reply

Join Date: Dec 2007
Posts: 21
Reputation: Lynxus is an unknown quantity at this point 
Solved Threads: 0
Lynxus Lynxus is offline Offline
Newbie Poster

Delphi Timer with Pertol Pump (easy) Help needed

 
0
  #1
Jan 26th, 2008
I am working on a petrol pump display, I have read the sticky on homework help and therefore understand and will appreciate all the help that is given to me.

Basically when the Nozzle button is pressed I want it to start dispencing the petrol so the litres dispensed will go up which is controlled by inserting pictures that are in the same directory. My code is below and runs but the numbers take 10 seconds to change to each one and I don't understand how to implement a interval and so it works on a button, with the timer disabled until pressed, I have many ways but they don't work.

Pascal and Delphi Syntax (Toggle Plain Text)
  1. procedure TfrmPetrolDisplay.Timer1Timer(Sender: TObject);
  2. Var
  3. LitresStr:String;
  4. n1:char;
  5. n2:char;
  6. n3:char;
  7. begin
  8. Litres:=Litres+1;
  9. LitresStr:=IntToStr(litres);
  10.  
  11. While Length(litresStr) <=3 do
  12. LitresStr:='0'+LitresStr;
  13.  
  14. n1:=LitresStr[1];
  15. n2:=LitresStr[2];
  16. n3:=LitresStr[3];
  17. Begin
  18. Case n1 Of
  19. '0':Img1.picture.loadfromfile('0.bmp');
  20. '1':Img1.picture.loadfromfile('1.bmp');
  21. '2':Img1.picture.loadfromfile('2.bmp');
  22. '3':Img1.picture.loadfromfile('3.bmp');
  23. '4':Img1.picture.loadfromfile('4.bmp');
  24. '5':Img1.picture.loadfromfile('5.bmp');
  25. '6':Img1.picture.loadfromfile('6.bmp');
  26. '7':Img1.picture.loadfromfile('7.bmp');
  27. '8':Img1.picture.loadfromfile('8.bmp');
  28. '9':Img1.picture.loadfromfile('9.bmp');
  29. End;
  30.  
  31. Begin
  32. Case n2 Of
  33. '0':Img2.picture.loadfromfile('0.bmp');
  34. '1':Img2.picture.loadfromfile('1.bmp');
  35. '2':Img2.picture.loadfromfile('2.bmp');
  36. '3':Img2.picture.loadfromfile('3.bmp');
  37. '4':Img2.picture.loadfromfile('4.bmp');
  38. '5':Img2.picture.loadfromfile('5.bmp');
  39. '6':Img2.picture.loadfromfile('6.bmp');
  40. '7':Img2.picture.loadfromfile('7.bmp');
  41. '8':Img2.picture.loadfromfile('8.bmp');
  42. '9':Img2.picture.loadfromfile('9.bmp');
  43. End;
  44.  
  45. Begin
  46. Case n3 Of
  47. '0':Img3.picture.loadfromfile('0.bmp');
  48. '1':Img3.picture.loadfromfile('1.bmp');
  49. '2':Img3.picture.loadfromfile('2.bmp');
  50. '3':Img3.picture.loadfromfile('3.bmp');
  51. '4':Img3.picture.loadfromfile('4.bmp');
  52. '5':Img3.picture.loadfromfile('5.bmp');
  53. '6':Img3.picture.loadfromfile('6.bmp');
  54. '7':Img3.picture.loadfromfile('7.bmp');
  55. '8':Img3.picture.loadfromfile('8.bmp');
  56. '9':Img3.picture.loadfromfile('9.bmp');
  57. End;
  58. End;
  59. End;
  60. End;
  61. End;
  62. end.

Thanks, all help appreciated.
Last edited by Lynxus; Jan 26th, 2008 at 8:13 pm.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,951
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Delphi Timer with Pertol Pump (easy) Help needed

 
0
  #2
Jan 26th, 2008
Are you saying that it takes 10 seconds for each digit? Or for each change in numbers?

If the latter, make sure you set the timer1.interval property to something relatively low, like 200 milliseconds.

If the former, you'll get a better response by loading all the images once, then just changing the image displayed. You can also avoid some repetition by creatively using some arrays.

For example:
  1. type
  2. TfrmPetrolDisplay = class( TForm )
  3. private
  4. f_images: array[ 1..3 ] of tImage;
  5. f_digits: array[ 0..9 ] of tBitmap;
  6. ...
  7. end;
  8.  
  9. ...
  10.  
  11. procedure TfrmPetrolDisplay.FormCreate( sender: tObject );
  12. var cntr: integer;
  13. begin
  14. // Initialize our "easy access" images array
  15. f_images[ 1 ] := Img1;
  16. f_images[ 2 ] := Img2;
  17. f_images[ 3 ] := Img3;
  18.  
  19. // Load all bitmaps from file or resource or wherever you keep them
  20. // (this example loads from file)
  21. for cntr := 0 to 9 do begin
  22. f_digits[ cntr ] := tBitmap.create;
  23. f_digits[ cntr ].loadFromFile( intToStr( cntr ) +'.bmp' )
  24. end
  25. end;
  26.  
  27. ...
  28.  
  29. procedure TfrmPetrolDisplay.FormDestroy( sender: tObject );
  30. var cntr: integer;
  31. begin
  32. // clean up our digits images
  33. for cntr := 0 to 9 do f_digits[ cntr ].free
  34. end;
  35.  
  36. ...
  37.  
  38. procedure TfrmPetrolDisplay.Timer1Timer( sender: tObject );
  39. var
  40. cntr: integer;
  41. LitresStr: string;
  42. begin
  43. Litres := Litres +1;
  44.  
  45. // Convert number of liters to a 3-digit number
  46. LitresStr := intToStr( Litres );
  47. LitresStr := stringOfChar( '0', 3 -length( LitresStr ) ) +LitresStr;
  48.  
  49. // Set each of the displayed digit images
  50. for cntr := 1 to 3 do
  51. f_images[ cntr ].picture.bitmap.assign( f_digits[ cntr ] )
  52. end;

To start and stop a timer, just set the timer1.enabled property to true or false.

Hope this helps.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 21
Reputation: Lynxus is an unknown quantity at this point 
Solved Threads: 0
Lynxus Lynxus is offline Offline
Newbie Poster

Re: Delphi Timer with Pertol Pump (easy) Help needed

 
0
  #3
Jan 27th, 2008
I tried your way but I just can't get it to work, my way works I just need to implement a timer in correctly and I don't understand how. Because there is no interval at the moment in my code, it takes 10 seconds to change from 0.00 to 0.01 then 10 seconds from 0.01 to 0.02 etc.

I kind of need my code to just be edited or someone to explain how to implement a timer.

Again much help appreciated from anyone ,
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,951
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Delphi Timer with Pertol Pump (easy) Help needed

 
0
  #4
Jan 27th, 2008
Originally Posted by Duoas
make sure you set the timer1.interval property to something relatively low, like 200 milliseconds.
Originally Posted by Duoas
To start and stop a timer, just set the timer1.enabled property to true or false.
123456789
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 21
Reputation: Lynxus is an unknown quantity at this point 
Solved Threads: 0
Lynxus Lynxus is offline Offline
Newbie Poster

Re: Delphi Timer with Pertol Pump (easy) Help needed

 
0
  #5
Jan 27th, 2008
Alright it seems to be working now although it wasn't yesterday lol. Thanks very much.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Pascal and Delphi Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC