•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Pascal and Delphi section within the Software Development category of DaniWeb, a massive community of 422,663 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,657 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Pascal and Delphi advertiser: Programming Forums
Views: 1798 | Replies: 22
![]() |
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,875
Reputation:
Rep Power: 11
Solved Threads: 193
OK, I've looked it over and made some fixes.
Your first problem was that you had the timer interval set to 1 millisecond. That's too fast. I bumped it up to a half-second.
You should avoid using more than one timer for the same event. I removed the second timer and combined the timer1timer and timer2timer procedures.
The second problem has to do with handling your data and converting between string and number. Check out the code for commentary on that.
I would recommend that you fix the TfrmPump.Litres to be a real value... or rename it to match its value (like TenthsOfLitre).
I fixed your forms to center themselves on the screen, and adjusted the text layout a little on the main form (so that it centers itself automatically). Oh yeah, I also changed text color to white so I could read it...
Lastly, your main form uses a non-standard font. My XP just recently crashed and I restored it from a backup image, so at the moment I don't have any fonts other than Microsoft defaults. Generally, if you must use a non-standard font for titles, use an image instead.
Some suggestions:
Don't use globals if you can avoid it. I notice you've got buttons to lift and seat the pump handle. Make yourself a boolean variable and stick it in the class definition (where I moved your Litres and ThisSale variables). Then, in the timer1timer procedure start off with:
Make sure to initialize values. The new variable (that I called "OkToPump") should be initialized in the FormCreate procedure. Likewise, you should have a default price per litre.
The ThisSale and Litres variables should be reset (to zero) when you lift the pump handle.
Well, that's all I can think of ATM. If you have any questions just ask.
Hope this helps.
Your first problem was that you had the timer interval set to 1 millisecond. That's too fast. I bumped it up to a half-second.
You should avoid using more than one timer for the same event. I removed the second timer and combined the timer1timer and timer2timer procedures.
The second problem has to do with handling your data and converting between string and number. Check out the code for commentary on that.
I would recommend that you fix the TfrmPump.Litres to be a real value... or rename it to match its value (like TenthsOfLitre).
I fixed your forms to center themselves on the screen, and adjusted the text layout a little on the main form (so that it centers itself automatically). Oh yeah, I also changed text color to white so I could read it...
Lastly, your main form uses a non-standard font. My XP just recently crashed and I restored it from a backup image, so at the moment I don't have any fonts other than Microsoft defaults. Generally, if you must use a non-standard font for titles, use an image instead.
Some suggestions:
Don't use globals if you can avoid it. I notice you've got buttons to lift and seat the pump handle. Make yourself a boolean variable and stick it in the class definition (where I moved your Litres and ThisSale variables). Then, in the timer1timer procedure start off with:
if not OkToPump then exit;Make sure to initialize values. The new variable (that I called "OkToPump") should be initialized in the FormCreate procedure. Likewise, you should have a default price per litre.
The ThisSale and Litres variables should be reset (to zero) when you lift the pump handle.
Well, that's all I can think of ATM. If you have any questions just ask.
Hope this helps.
Last edited by Duoas : Feb 12th, 2008 at 8:45 pm.
•
•
Join Date: Dec 2007
Posts: 21
Reputation:
Rep Power: 1
Solved Threads: 0
Okay you have helped very much and I appreciate that and understand why all my code has been changed so it has improved my understanding.
The only thing that I need to explain to you now that I dont get either is the way the price per litre works in the UK.
You are right that we have pounds and pence and there are 100 pence in a pound. at a petrol station though the price of 1 litre would be 104.9 or something.
this means 1 pound, 4 pence and .9 of a pence.
99.8 = 99 pence and .8 of a pence.
111.5 = 1 pound, 11 pence and .5 of a pence.
Kind of confusing but I hope you understand because I don't see how that would run.
Thanks very much and I hope you can solve this major problem in the logic of the way the pump runs.
The only thing that I need to explain to you now that I dont get either is the way the price per litre works in the UK.
You are right that we have pounds and pence and there are 100 pence in a pound. at a petrol station though the price of 1 litre would be 104.9 or something.
this means 1 pound, 4 pence and .9 of a pence.
99.8 = 99 pence and .8 of a pence.
111.5 = 1 pound, 11 pence and .5 of a pence.
Kind of confusing but I hope you understand because I don't see how that would run.
Thanks very much and I hope you can solve this major problem in the logic of the way the pump runs.
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,875
Reputation:
Rep Power: 11
Solved Threads: 193
Ah, I get it. So the price is listed in pence, not pounds sterling.
Yes, they use the same daft trick here in the USA. You get
You'll have to update your code to obtain and display the price per litre in pence, then divide by 100 to get the price per litre in pounds. If it gives you trouble let me know.
(Take your time in thinking about what units each of your variables represents: Litres, ThisSale, and PriceLitre.)
Hope this helps.
Yes, they use the same daft trick here in the USA. You get
104.9 (in pence) and we get 1.049 (in dollars). The decimal point is just put in a different spot since the units differ.You'll have to update your code to obtain and display the price per litre in pence, then divide by 100 to get the price per litre in pounds. If it gives you trouble let me know.
(Take your time in thinking about what units each of your variables represents: Litres, ThisSale, and PriceLitre.)
Hope this helps.
•
•
Join Date: Sep 2007
Posts: 69
Reputation:
Rep Power: 2
Solved Threads: 7
You appear to have got a nice conversation going Lynxus & Duos so I hesitate to butt in. However, having looked at the original post there are a few issues that struck me so I thought I would comment.
If you want to figure out some of the Math involved in programming such a display I have a CSS version of it here
http://www.explainth.at/en/css/csscapt.shtml
- Running a case statement block each time you want to change a digit and then loading multiple images from file does not sound like a great way to do things.
- A better approach would be to overlay all digits, 0-9, one on top of the other for each number in your display. Set their visibility to false and on each tick of your timer simply set it to true for the digit to be displayed.
- A better approach would be not to use images at all - it is pretty easy to create a calculator-style 7 segment display using aligned shapes inside a panel. With that done all you need to do on each timer tick is to show/hide the relevant segments for each digit. I am suggesting this beause I am assuming that you cannot simply use a 7-seg LED component (plenty of those around and I have one of my own somewhere)
If you want to figure out some of the Math involved in programming such a display I have a CSS version of it here
http://www.explainth.at/en/css/csscapt.shtml
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,875
Reputation:
Rep Power: 11
Solved Threads: 193
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,875
Reputation:
Rep Power: 11
Solved Threads: 193
Since PriceLitre is in pounds sterling (but displayed in pence), I just adjusted the math in the program to convert behind the scenes.
A case statement is just a selector returning a single item. There is no iteration involved...
Your program produces the animation by changing all the numbers once per timer timeout.
Hope this helps.
Pascal Syntax (Toggle Plain Text)
try // convert to pence (string) to pounds (real) PriceLitre := StrToFloat( PriceLitreedt.text ) /100; except on EConvertError do ... // (stuff you already have is omitted here) end; ... // (stuff you already have is omitted here) // Convert the validated pounds sterling to a string // representing pence and tenths-pence PriceLitreStr := FormatFloat( '000.0', PriceLitre *100 ); // Load the images Img15.picture.loadfromfile( PriceLitreStr[1] +'.bmp' ); ...
A case statement is just a selector returning a single item. There is no iteration involved...
Your program produces the animation by changing all the numbers once per timer timeout.
Hope this helps.
•
•
Join Date: Apr 2005
Location: Old Hampshire, Old England (LOL)
Posts: 11,937
Reputation:
Rep Power: 30
Solved Threads: 267
•
•
Join Date: Dec 2007
Posts: 21
Reputation:
Rep Power: 1
Solved Threads: 0
Okay I understand now, a case statement was a rather long way of going round. Thanks a lot, it's all working fine now
.
The only thing that I don't understand is this...
Begin
try
PriceLitre := StrToFloat(PriceLitreedt.text) /100;
except on EConvertError do
What is that...could you just explain the bolded part and perhaps why it's there?
.The only thing that I don't understand is this...
Begin
try
PriceLitre := StrToFloat(PriceLitreedt.text) /100;
except on EConvertError do
What is that...could you just explain the bolded part and perhaps why it's there?
Last edited by Lynxus : Feb 13th, 2008 at 2:28 pm.
![]() |
•
•
•
•
•
•
•
•
DaniWeb Pascal and Delphi Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Previous Thread: how to connect SQL database through delphi?
- Next Thread: How do you change file owner in Delphi?



Linear Mode