User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: Dec 2007
Posts: 21
Reputation: Lynxus is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Lynxus Lynxus is offline Offline
Newbie Poster

Re: Help With Delphi Petrol Pump Logic.

  #11  
Feb 12th, 2008
Okay thanks, I will keep an eye out. E-mail me the too if you like, either way i will get it.
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,875
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 11
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Help With Delphi Petrol Pump Logic.

  #12  
Feb 12th, 2008
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:
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.
Reply With Quote  
Join Date: Dec 2007
Posts: 21
Reputation: Lynxus is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Lynxus Lynxus is offline Offline
Newbie Poster

Re: Help With Delphi Petrol Pump Logic.

  #13  
Feb 12th, 2008
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.
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,875
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 11
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Help With Delphi Petrol Pump Logic.

  #14  
Feb 12th, 2008
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 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.
Reply With Quote  
Join Date: Sep 2007
Posts: 69
Reputation: ExplainThat is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 7
ExplainThat ExplainThat is offline Offline
Junior Poster in Training

Re: Help With Delphi Petrol Pump Logic.

  #15  
Feb 13th, 2008
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.
  • 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
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,875
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 11
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Help With Delphi Petrol Pump Logic.

  #16  
Feb 13th, 2008
Yeah, we've already discussed this. I've already replaced his big case statements with a single line of code each...

The best fix is to have an array of bitmaps (obtained either from hidden images on the form, or from resource, or by using a TImageList), and assigning the image as appropriate.
Reply With Quote  
Join Date: Dec 2007
Posts: 21
Reputation: Lynxus is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Lynxus Lynxus is offline Offline
Newbie Poster

Re: Help With Delphi Petrol Pump Logic.

  #17  
Feb 13th, 2008
Okay well now I don't really understand how to get the this sale working properly...

Also I used a case statement because it was the easiest way to have it run through all the digits like a real petrol pump does but this way seems more simple so I guess it's fine.
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,875
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 11
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Help With Delphi Petrol Pump Logic.

  #18  
Feb 13th, 2008
Since PriceLitre is in pounds sterling (but displayed in pence), I just adjusted the math in the program to convert behind the scenes.
  1. try
  2. // convert to pence (string) to pounds (real)
  3. PriceLitre := StrToFloat( PriceLitreedt.text ) /100;
  4. except on EConvertError do
  5. ... // (stuff you already have is omitted here)
  6. end;
  7.  
  8. ... // (stuff you already have is omitted here)
  9.  
  10. // Convert the validated pounds sterling to a string
  11. // representing pence and tenths-pence
  12. PriceLitreStr := FormatFloat( '000.0', PriceLitre *100 );
  13.  
  14. // Load the images
  15. Img15.picture.loadfromfile( PriceLitreStr[1] +'.bmp' );
  16. ...

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.
Reply With Quote  
Join Date: Apr 2005
Location: Old Hampshire, Old England (LOL)
Posts: 11,937
Reputation: jbennet is a jewel in the rough jbennet is a jewel in the rough jbennet is a jewel in the rough jbennet is a jewel in the rough 
Rep Power: 30
Solved Threads: 267
Moderator
Featured Poster
jbennet's Avatar
jbennet jbennet is offline Offline
Microsoft Fanboy

Re: Help With Delphi Petrol Pump Logic.

  #19  
Feb 13th, 2008
Are you doing AS computing?
TRY MY SUGGESTIONS AT YOUR OWN RISK!
james.bennet1@ntlworld.com
Reply With Quote  
Join Date: Dec 2007
Posts: 21
Reputation: Lynxus is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Lynxus Lynxus is offline Offline
Newbie Poster

Re: Help With Delphi Petrol Pump Logic.

  #20  
Feb 13th, 2008
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?
Last edited by Lynxus : Feb 13th, 2008 at 2:28 pm.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Pascal and Delphi Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the Pascal and Delphi Forum

All times are GMT -4. The time now is 4:21 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC