Lynxus 0 Newbie Poster

Okay but I was just interested in knowing what that bit of code does.

Lynxus 0 Newbie Poster

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?

Lynxus 0 Newbie Poster

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.

Lynxus 0 Newbie Poster

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.

Lynxus 0 Newbie Poster

Okay thanks, I will keep an eye out. E-mail me the too if you like, either way i will get it.

Lynxus 0 Newbie Poster

alright I thought you would. I will do that now.

Lynxus 0 Newbie Poster

I sent an e-mail so I hope you got it. :).

Lynxus 0 Newbie Poster

Well I've tried to PM you more of my code and it doesnt work. Do you have an e-mail I can send to because I dont really want to post all my code here.

Now it will run the litres round at an interval of 1.
So it will go from 00.1 to 00.2...

And the price of the sale should go round the same showing every number but faster because of what the price per litre is.e.g. when the litres is at exactly 01.0 then the price of the sale should show 001.00 if the price per litre is 100.0.

Lynxus 0 Newbie Poster

string[5] is just to keep it simple and limited, Do you have msn? it will be much easier to explain my problem there.

Lynxus 0 Newbie Poster

I have a Petrol Pump system that runs a timer that simulates the litres that run and the display shows the images inserting into an image box. Then the Price at current is the litres * the set price per litre.

Thats where the problem is because I can't get the Price of the sale working.

I understand the fact of helping with homework and that you won't just do it all for me, if you want to ask more questions then PM me and you can get my MSN if you need to explain in person.

procedure TfrmPump.Timer2Timer(Sender: TObject);
var
 n1,n2,n3,n4,n5:char;
 thissalestr,tempstr:string[5];
 i:integer;


begin
  thissale:= (PriceLitre)*(litres/10) ;
  thissaleStr:=floattostr(thissale);

for i:=1 to length(thissalestr) DO
  IF    thissalestr <> '.' THEN
    tempstr:=tempstr+ thissalestr;

begin

  While Length(tempstr) <5 do
 tempstr:='0'+tempstr;

  Begin
  n1:=thissaleStr[1];
  n2:=thissaleStr[2];
  n3:=thissaleStr[3];
  n4:=thissaleStr[4];
  n5:=thissaleStr[5];

Case n1 of
  '0':Img1.picture.loadfromfile('0.bmp');
  '1':Img1.picture.loadfromfile('1.bmp');
  '2':Img1.picture.loadfromfile('2.bmp');
  '3':Img1.picture.loadfromfile('3.bmp');
  '4':Img1.picture.loadfromfile('4.bmp');
  '5':Img1.picture.loadfromfile('5.bmp');
  '6':Img1.picture.loadfromfile('6.bmp');
  '7':Img1.picture.loadfromfile('7.bmp');
  '8':Img1.picture.loadfromfile('8.bmp');
  '9':Img1.picture.loadfromfile('9.bmp');
End;

Case n2 of
  '0':Img2.picture.loadfromfile('0.bmp');
  '1':Img2.picture.loadfromfile('1.bmp');
  '2':Img2.picture.loadfromfile('2.bmp');
  '3':Img2.picture.loadfromfile('3.bmp');
  '4':Img2.picture.loadfromfile('4.bmp');
  '5':Img2.picture.loadfromfile('5.bmp');
  '6':Img2.picture.loadfromfile('6.bmp');
  '7':Img2.picture.loadfromfile('7.bmp');
  '8':Img2.picture.loadfromfile('8.bmp');
  '9':Img2.picture.loadfromfile('9.bmp');

End;

Case n3 of
  '0':Img3.picture.loadfromfile('0.bmp');
  '1':Img3.picture.loadfromfile('1.bmp');
  '2':Img3.picture.loadfromfile('2.bmp');
  '3':Img3.picture.loadfromfile('3.bmp');
  '4':Img3.picture.loadfromfile('4.bmp');
  '5':Img3.picture.loadfromfile('5.bmp');
  '6':Img3.picture.loadfromfile('6.bmp');
  '7':Img3.picture.loadfromfile('7.bmp');
  '8':Img3.picture.loadfromfile('8.bmp');
  '9':Img3.picture.loadfromfile('9.bmp');
End;

Case n4 of
  '0':Img4.picture.loadfromfile('0.bmp');
  '1':Img4.picture.loadfromfile('1.bmp');
  '2':Img4.picture.loadfromfile('2.bmp');
  '3':Img4.picture.loadfromfile('3.bmp');
  '4':Img4.picture.loadfromfile('4.bmp');
  '5':Img4.picture.loadfromfile('5.bmp');
  '6':Img4.picture.loadfromfile('6.bmp');
  '7':Img4.picture.loadfromfile('7.bmp');
  '8':Img4.picture.loadfromfile('8.bmp');
  '9':Img4.picture.loadfromfile('9.bmp');

end;

Case n5 of
  '0':Img5.picture.loadfromfile('0.bmp');
  '1':Img5.picture.loadfromfile('1.bmp');
  '2':Img5.picture.loadfromfile('2.bmp');
  '3':Img5.picture.loadfromfile('3.bmp');
  '4':Img5.picture.loadfromfile('4.bmp');
  '5':Img5.picture.loadfromfile('5.bmp');
  '6':Img5.picture.loadfromfile('6.bmp');
  '7':Img5.picture.loadfromfile('7.bmp');
  '8':Img5.picture.loadfromfile('8.bmp');
  '9':Img5.picture.loadfromfile('9.bmp');

end;
end;
end;
end;

end.
Lynxus 0 Newbie Poster

TPrices is a Record.

And at school we've been through that same guide but it is useful, it's just a case of reminding myself I think.

Lynxus 0 Newbie Poster

Okay well I entered in the code and PricePerLitre I haven't declared atall. What do I declare it as because whatever I put it doesn't seem to work,
Also what do I put in the form destroy procedure because I'm not sure what I posted up there is completely right?

from there I think I can do the rest.

Thanks very much :)

Lynxus 0 Newbie Poster

Ok. Thanks for your quick reply, I didn't expect one so quick so wasn't checking :P. Here is some code I have come up with although it doesn't quite work because I don't know much about file handling.

procedure TfrmCashier.btnSubmitSpeedOfDispenceClick(Sender: TObject);
begin
  SpeedOfDispence:=1;
end;

procedure TfrmCashier.FormCreate(Sender: TObject);
var
 NewPriceRec : TPrices;
 filePricerec : TPrices;
begin
  assignfile(Pricesfile,'Staff.dat');
  rewrite(Pricesfile);
 with NewPriceRec do
  begin
  PricePerLitre:=PriceLitreEdt.Text;
  closefile(Pricesfile);
end;
end;

procedure TfrmCashier.FormDestroy(Sender: TObject);
begin
  assignfile(Pricesfile,'Staff.dat');
  rewrite(Pricesfile);
  write(Pricesfile)
end;

End.
Lynxus 0 Newbie Poster

I have a petrol pump simulator system and the Price Per Litre is entered through an Edit box and then the Images for each digit is displayed in an Imagebox. That part works fine, but however eachtime the application is closed the Price per litre is reset and It has to be re-entered, I would like it to be rememberd so that when I open Delphi again it will already be set.

I understand the rules and don't expect all the code to just be given to me I just need help on understanding how to go about this.

Thanks, all help appreciated :).

Lynxus 0 Newbie Poster

Alright it seems to be working now although it wasn't yesterday :) lol. Thanks very much.

Lynxus 0 Newbie Poster

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 :),

Lynxus 0 Newbie Poster

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.

procedure TfrmPetrolDisplay.Timer1Timer(Sender: TObject);
Var
  LitresStr:String;
  n1:char;
  n2:char;
  n3:char;
begin
  Litres:=Litres+1;
  LitresStr:=IntToStr(litres);

While Length(litresStr) <=3 do
  LitresStr:='0'+LitresStr;

n1:=LitresStr[1];
n2:=LitresStr[2];
n3:=LitresStr[3];
Begin
Case n1 Of
'0':Img1.picture.loadfromfile('0.bmp');
'1':Img1.picture.loadfromfile('1.bmp');
'2':Img1.picture.loadfromfile('2.bmp');
'3':Img1.picture.loadfromfile('3.bmp');
'4':Img1.picture.loadfromfile('4.bmp');
'5':Img1.picture.loadfromfile('5.bmp');
'6':Img1.picture.loadfromfile('6.bmp');
'7':Img1.picture.loadfromfile('7.bmp');
'8':Img1.picture.loadfromfile('8.bmp');
'9':Img1.picture.loadfromfile('9.bmp');
End;

Begin
Case n2 Of
'0':Img2.picture.loadfromfile('0.bmp');
'1':Img2.picture.loadfromfile('1.bmp');
'2':Img2.picture.loadfromfile('2.bmp');
'3':Img2.picture.loadfromfile('3.bmp');
'4':Img2.picture.loadfromfile('4.bmp');
'5':Img2.picture.loadfromfile('5.bmp');
'6':Img2.picture.loadfromfile('6.bmp');
'7':Img2.picture.loadfromfile('7.bmp');
'8':Img2.picture.loadfromfile('8.bmp');
'9':Img2.picture.loadfromfile('9.bmp');
End;

Begin
Case n3 Of
'0':Img3.picture.loadfromfile('0.bmp');
'1':Img3.picture.loadfromfile('1.bmp');
'2':Img3.picture.loadfromfile('2.bmp');
'3':Img3.picture.loadfromfile('3.bmp');
'4':Img3.picture.loadfromfile('4.bmp');
'5':Img3.picture.loadfromfile('5.bmp');
'6':Img3.picture.loadfromfile('6.bmp');
'7':Img3.picture.loadfromfile('7.bmp');
'8':Img3.picture.loadfromfile('8.bmp');
'9':Img3.picture.loadfromfile('9.bmp');
End;
End;
End;
End;
End;
end.

Thanks, all help appreciated.

Lynxus 0 Newbie Poster

Yeah thanks, but he said we are going to go into more depths with delphi and not to go into them yet. I'm getting on with it though and think i'm almost done...

Lynxus 0 Newbie Poster

You are correct that I have came from a pascal background, however the assignment requires me to use what I've learned in pascal and some delphi to do this.

Thanks for your help.

Lynxus 0 Newbie Poster
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TNewFileNameLbl = class(TForm)
    EmployLbl: TLabel;
    Surname: TLabel;
    ForenameLbl: TLabel;
    SalaryLbl: TLabel;
    SurnameEdt: TEdit;
    ForenameEdt: TEdit;
    SalaryEdt: TEdit;
    EmployEdt: TEdit;
    Savebtn: TButton;
    ClearBtn: TButton;
    ReloadBtn: TButton;
    EraseBtn: TButton;
    RenameEdt: TButton;
    NewFileNameLbl: TLabel;
    NewFileNameEdt: TEdit;
    procedure ClearBtnClick(Sender: TObject);
    procedure SavebtnClick(Sender: TObject);
    procedure ReloadBtnClick(Sender: TObject);
    procedure EraseBtnClick(Sender: TObject);
    procedure RenameEdtClick(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  End;
    Employees=record
    EmployeeID:String[5];
    Surname:string[20];
    Forename:string[20];
    salary:string[8];
  end;

var
  NewFileNameLbl: TNewFileNameLbl;
  Employee:Employees;
  Employeesrecord:Employees;
  EmployeeFile:File of Employees;

implementation
{$R *.dfm}

procedure TNewFileNameLbl.ClearBtnClick(Sender: TObject);
begin
    Employedt.text:='';
    Surnameedt.text:='';
    Forenameedt.text:='';
    salaryedt.text:='';
end;

procedure TNewFileNameLbl.SaveBtnClick(Sender: TObject);
var
  Employeefile:file of Employees;

begin
Assignfile(employeefile, 'staff.dat');

IF FileExists('staff.dat') THEN
  RESET(EmployeeFile)
ELSE
  REWRITE(EmployeeFile);

  WITH Employeesrecord DO
  begin
    EmployeeID:=Employedt.text;
    Surname:=Surnameedt.text;
    Forename:=Forenameedt.text;
    salary:=salaryedt.text;

  end;

  assignfile(Employeefile,'staff.dat');
  reset(Employeefile);
  Seek(Employeefile,filesize(Employeefile));
  write(Employeefile,Employeesrecord);
  closefile(Employeefile);

end;

procedure TNewFileNameLbl.reloadBtnClick(Sender: TObject);

var
  Employeefile:file of Employees;

begin
  assignfile(Employeefile,'staff.dat');
  reset(Employeefile);
  read(Employeefile,Employeesrecord);
  closefile(Employeefile);

with Employeesrecord do
  begin
    EmployEdt.text:=EmployeeID;
    Surnameedt.text:=Surname;
    Forenameedt.text:=Forename;
    salaryedt.text:=salary;
  end;
end;

procedure TNewFileNameLbl.EraseBtnClick(Sender: TObject);
Var
EmployeeFile:TextFile;
begin
  AssignFile(EmployeeFile, 'staff.dat');
  Rewrite(EmployeeFile);
  CloseFile(EmployeeFile);
  Erase(EmployeeFile);
end;

procedure TNewFileNameLbl.RenameEdtClick(Sender: TObject);
var
  EmployeeFile:TextFile;
  text:string;

begin
  AssignFile(EmployeeFile, 'staff.dat');
  ReWrite(EmployeeFile);
  CloseFile(EmployeeFile);
  DeleteFile('NewName.txt');
  Rename(EmployeeFile, 'NewName.txt');
  AssignFile(EmployeeFile, 'NewName.txt');
  Reset(EmployeeFile);
while not Eof(EmployeeFile) do
  begin
    ReadLn(EmployeeFile, text);
    ShowMessage(text);
  end;
  CloseFile(EmployeeFile);

end;

end.

I know I'm new but I plan to stick around and get better and help out as much as I can, I can't get better without help,

Thanks, much appreciated.

Lynxus 0 Newbie Poster

I don't know what the proper name is for it lol, but I have an assignment. I am fairly new to delphi. I understand the homework rules so I don't expect it all to be done I just need help in the understanding and feel free to help as much as you want.

Create a delphi program that will allow a user to save employee details. The system should save an employeeID, surname, forname and salary.

I appreciate any help given...
This is the assignment details

Requirements
store an employee record with the attributes employeeID, surname, forname and salary;
be able to add a new record;
be able to view a record;
provide navigation to move one record forward and one record back (use seek)
be able to delete a record;

The file must be saved in sequential order which means you will need to write an algorithm for correctly inserting the record. You will also add a button to delete a record based on the key field a user selects.

I have done some but I can't get it at the moment because of some server problem. The part I need help with is the sequntial ordering and a pointer to make the files viewable and go to next and previous.