I'm trying to make a checkout system but i'm having trouble with one part and cannot think of a solution for the life of me.

Basically when you enter the checkout form it displays the items for sale (because on another form you enter the details of an item for sale and then they are stored to ProductButton file so when you open up the checkout it displays the correct amount of buttns with the name of the item as the caption so if you add one item to the File it will show one button, two items two buttons ect ect) now the problem is when there is one button it works fine you press the button and it displays the price on the reciept but when there are two items the first button no longer does anything but the second button works and when theres three buttons the first two no longer do anything.

sorry it's a vague description of the problem but i don't realli know how to explain it

heres the code any help or comments would be majorly appreciated :-

unit Unit13;

interface

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

type
  TForm13 = class(TForm)
    XPManifest1: TXPManifest;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Label1: TLabel;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    Button7: TButton;
    Button8: TButton;
    Button9: TButton;
    Button10: TButton;
    Button11: TButton;
    Button12: TButton;
    Button13: TButton;
    Button14: TButton;
    Button15: TButton;
    Button16: TButton;
    Button17: TButton;
    Button18: TButton;
    Button19: TButton;
    Button20: TButton;
    Button21: TButton;
    Button22: TButton;
    Button23: TButton;
    Button24: TButton;
    Button25: TButton;
    Button26: TButton;
    Button27: TButton;
    Button28: TButton;
    Button29: TButton;
    Button30: TButton;
    Button31: TButton;
    Button32: TButton;
    Button33: TButton;
    Button34: TButton;
    Button35: TButton;
    Button36: TButton;
    Button37: TButton;
    Button38: TButton;
    Button39: TButton;
    Button40: TButton;
    Button41: TButton;
    Label2: TLabel;
    Recipt: TRichEdit;
    Button42: TButton;
    Button43: TButton;
    Button44: TButton;
    Button45: TButton;
    Button46: TButton;
    Button47: TButton;
    Button48: TButton;
    Button49: TButton;
    Button50: TButton;
    Button51: TButton;
    Button52: TButton;
    Button53: TButton;
    Button54: TButton;
    Button55: TButton;
    Button56: TButton;
    Button57: TButton;
    Button58: TButton;
    Button59: TButton;
    Button60: TButton;
    Button61: TButton;
    Button62: TButton;
    Button63: TButton;
    Button64: TButton;
    Button65: TButton;
    Button66: TButton;
    Button67: TButton;
    Button68: TButton;
    Button69: TButton;
    Button70: TButton;
    Button71: TButton;
    Button72: TButton;
    Button73: TButton;
    Button74: TButton;
    Button75: TButton;
    Button76: TButton;
    Button77: TButton;
    Button78: TButton;
    Button79: TButton;
    Button80: TButton;
    Button81: TButton;
    procedure FormActivate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button42Click(Sender: TObject);
    procedure Buy;
    procedure Rentit;
    procedure Buyit;
    procedure Normalshow;
    procedure Rentshow;
    procedure Buttondisplay1;
    procedure Buttondisplay2;
    procedure Buttondisplay3;
    procedure Buttondisplay4;
    procedure Buttondisplay5;
    procedure Buttondisplay6;
    procedure Buttondisplay7;
    procedure Buttondisplay8;
    procedure Buttondisplay9;
    procedure Buttondisplay10;
    procedure Buttondisplay11;
    procedure Buttondisplay12;
    procedure Buttondisplay13;
    procedure Buttondisplay14;
    procedure Buttondisplay15;
    procedure Buttondisplay16;
    procedure Buttondisplay17;
    procedure Buttondisplay18;
    procedure Buttondisplay19;
    procedure Buttondisplay20;
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form13: TForm13;
  ButtonCaption : String;

implementation

uses unit7, unit4, unit34;

{$R *.dfm}

procedure TForm13.FormActivate(Sender: TObject);
begin
If unit7.Renting = true then
  Rentshow
Else
  Normalshow
End;

Procedure TForm13.Normalshow;
var button : integer;
begin
  button := 0;
  form13.Caption := form7.Button1.Caption;
  label1.Caption := form13.Caption;
  Recipt.Text := form7.RichEdit1.Text;
  assignfile(ProductButtonFile, ProductButton);
  reset(ProductButtonFile);
  while not eof (ProductButtonFile) do
  Begin
  read(ProductButtonFile, ProductButtonRecord);
  If ProductButtonRecord.ProductCatagory = Form13.Caption then
  Begin
  button := button + 1;
    If button = 1 then
      Buttondisplay1;
    If button = 2 then
      Buttondisplay2;
    If button = 3 then
      Buttondisplay3;
    If button = 4 then
      Buttondisplay4;
    If button = 5 then
      Buttondisplay5;
    If button = 6 then
      Buttondisplay6;
    If button = 7 then
      Buttondisplay7;
    If button = 8 then
      Buttondisplay8;
    If button = 9 then
      Buttondisplay9;
    If button = 10 then
      Buttondisplay10;
    If button = 11 then
      Buttondisplay11;
    If button = 12 then
      Buttondisplay12;
    If button = 13 then
      Buttondisplay13;
    If button = 14 then
      Buttondisplay14;
    If button = 15 then
      Buttondisplay15;
    If button = 16 then
      Buttondisplay16;
    If button = 17 then
      Buttondisplay17;
    If button = 18 then
      Buttondisplay18;
    If button = 19 then
      Buttondisplay19;
    If button = 20 then
      Buttondisplay20;
  End;
  End;
  reset (ProductbuttonFile);
  closefile(ProductButtonFile);
end;

Procedure Tform13.Rentshow;
var button : integer;
begin
  button := 0;
  form13.Caption := form7.Button1.Caption;
  label1.Caption := form13.Caption;
  Recipt.Text := form7.RichEdit1.Text;
  assignfile(ProductButtonFile, ProductButton);
  reset(ProductButtonFile);
  while not eof (ProductButtonFile) do
  Begin
  read(ProductButtonFile, ProductButtonRecord);
  If (ProductButtonRecord.ProductCatagory = Form13.Caption) and (ProductButtonRecord.ProductRentalCheck = 'Y') then
  Begin
  button := button + 1;
    If button = 1 then
      Buttondisplay1;
    If button = 2 then
      Buttondisplay2;
    If button = 3 then
      Buttondisplay3;
    If button = 4 then
      Buttondisplay4;
    If button = 5 then
      Buttondisplay5;
    If button = 6 then
      Buttondisplay6;
    If button = 7 then
      Buttondisplay7;
    If button = 8 then
      Buttondisplay8;
    If button = 9 then
      Buttondisplay9;
    If button = 10 then
      Buttondisplay10;
    If button = 11 then
      Buttondisplay11;
    If button = 12 then
      Buttondisplay12;
    If button = 13 then
      Buttondisplay13;
    If button = 14 then
      Buttondisplay14;
    If button = 15 then
      Buttondisplay15;
    If button = 16 then
      Buttondisplay16;
    If button = 17 then
      Buttondisplay17;
    If button = 18 then
      Buttondisplay18;
    If button = 19 then
      Buttondisplay19;
    If button = 20 then
      Buttondisplay20;
  End;
  End;
  reset (ProductbuttonFile);
  closefile(ProductButtonFile);
end;


procedure TForm13.Button1Click(Sender: TObject);
begin
  form13.close;
  form7.Visible := true;
  Form7.RichEdit1.Text := Recipt.Text;
end;

procedure TForm13.Button42Click(Sender: TObject);
begin
  assignfile(ProductButtonFile, ProductButton);
  reset(ProductButtonFile);
    while not eof (ProductButtonFile) do
    read(ProductButtonFile, ProductButtonRecord);
      Begin
        If ProductButtonRecord.ProductName = Button2.Caption then
          Begin
            Recipt.Lines.Add(Button2.Caption + '                              ' + ProductbuttonRecord.ProductPrice);
            unit7.price[unit7.numberonrecipt] := strtofloat(ProductButtonRecord.ProductPrice);
            unit7.numberonrecipt := unit7.numberonrecipt + 1;
            unit7.void := unit7.void + 1;
          End;
      End;
    closefile(ProductButtonFile);
end;


procedure TForm13.Buy;
begin
If unit7.Renting = true then
    Rentit
  Else
    Buyit
End;

Procedure TForm13.Rentit;
  Begin
    assignfile(ProductButtonFile, ProductButton);
    reset(ProductButtonFile);
      while not eof (ProductButtonFile) do
      read(ProductButtonFile, ProductButtonRecord);
        Begin
          If (ProductButtonRecord.ProductRentalCheck = '') and (ProductButtonRecord.ProductName = ButtonCaption) then
            Begin
              //error message if product can't be hired
              showmessage('This Product cannot be Hired Out');
              closefile(ProductButtonFile);
            End
          Else
            //If the Product can be rented a second check is done to make sure
            Begin
              Assignfile(ProductButtonFile, ProductButton);
              reset(ProductButtonFile);
                While not eof (ProductButtonFile) do
                read(ProductButtonFile, ProductButtonRecord);
                  Begin
                    If (ProductButtonRecord.ProductRentalCheck = 'Y') and (ProductButtonRecord.ProductName = ButtonCaption) then
                      Begin
                        //If check passes Product Rental page is opened and fields are filled
                        Rentout.Visible := true;
                        Rentout.Edit1.Text := ButtonCaption;
                        Rentout.Edit2.Text := ProductButtonRecord.ProductRentalPrice
                      End;
                  End;
            End;
        End;
  End;

Procedure Tform13.Buyit;
  Begin
    assignfile(ProductButtonFile, ProductButton);
    reset(ProductButtonFile);
      while not eof (ProductButtonFile) do
      read(ProductButtonFile, ProductButtonRecord);
        Begin
          If ProductButtonRecord.ProductName = ButtonCaption then
            Begin
              recipt.Lines.add(ButtonCaption+'                              ' + ProductbuttonRecord.ProductPricenVAT);
              unit7.price[unit7.numberonrecipt] := strtofloat(ProductButtonRecord.ProductPricenVAT);
              unit7.numberonrecipt := unit7.numberonrecipt + 1;
              unit7.void := unit7.void + 1;
            End;
        End;
      closefile(ProductButtonFile);
  end;

Procedure Tform13.Buttondisplay1;
  Begin
    button2.Caption := ProductButtonRecord.ProductName;
    button2.Visible := true;
    button42.Visible := true;
  End;

Procedure TForm13.Buttondisplay2;
  Begin
    button3.Caption := ProductButtonRecord.ProductName;
    button3.Visible := true;
    button43.Visible := true;
  End;

Procedure Tform13.Buttondisplay3;
  Begin
    button4.Caption := ProductButtonRecord.ProductName;
    button4.Visible := true;
    button44.Visible := true;
  End;

Procedure Tform13.Buttondisplay4;
  Begin
    button5.Caption := ProductButtonRecord.ProductName;
    button5.Visible := true;
    button45.Visible := true;
  End;

Procedure Tform13.Buttondisplay5;
  Begin
    button6.Caption := ProductButtonRecord.ProductName;
    button6.Visible := true;
    button46.Visible := true;
  End;

Procedure Tform13.Buttondisplay6;
  Begin
    button7.Caption := ProductButtonRecord.ProductName;
    button7.Visible := true;
    button47.Visible := true;
  End;

Procedure Tform13.Buttondisplay7;
  Begin
    button8.Caption := ProductButtonRecord.ProductName;
    button8.Visible := true;
    button48.Visible := true;
  End;

Procedure Tform13.Buttondisplay8;
  Begin
    button9.Caption := ProductButtonRecord.ProductName;
    button9.Visible := true;
    button49.Visible := true;
  End;

Procedure Tform13.Buttondisplay9;
  Begin
    button10.Caption := ProductButtonRecord.ProductName;
    button10.Visible := true;
    button50.Visible := true;
  End;

Procedure Tform13.Buttondisplay10;
  Begin
    button11.Caption := ProductButtonRecord.ProductName;
    button11.Visible := true;
    button51.Visible := true;
  End;

Procedure Tform13.Buttondisplay11;
  Begin
    button12.Caption := ProductButtonRecord.ProductName;
    button12.Visible := true;
    button52.Visible := true;
  End;

Procedure Tform13.Buttondisplay12;
  Begin
    button13.Caption := ProductButtonRecord.ProductName;
    button13.Visible := true;
    button53.Visible := true;
  End;

Procedure Tform13.Buttondisplay13;
  Begin
    button14.Caption := ProductButtonRecord.ProductName;
    button14.Visible := true;
    button54.Visible := true;
  End;

Procedure Tform13.Buttondisplay14;
  Begin
    button15.Caption := ProductButtonRecord.ProductName;
    button15.Visible := true;
    button55.Visible := true;
  End;

Procedure Tform13.Buttondisplay15;
  Begin
    button16.Caption := ProductButtonRecord.ProductName;
    button16.Visible := true;
    button56.Visible := true;
  End;

Procedure Tform13.Buttondisplay16;
  Begin
    button17.Caption := ProductButtonRecord.ProductName;
    button17.Visible := true;
    button57.Visible := true;
  End;

Procedure Tform13.Buttondisplay17;
  Begin
    button18.Caption := ProductButtonRecord.ProductName;
    button18.Visible := true;
    button58.Visible := true;
  End;

Procedure Tform13.Buttondisplay18;
  Begin
    button19.Caption := ProductButtonRecord.ProductName;
    button19.Visible := true;
    button59.Visible := true;
  End;

Procedure Tform13.Buttondisplay19;
  Begin
    button20.Caption := ProductButtonRecord.ProductName;
    button20.Visible := true;
    button60.Visible := true;
  End;

Procedure Tform13.Buttondisplay20;
  Begin
    button21.Caption := ProductButtonRecord.ProductName;
    button21.Visible := true;
    button61.Visible := true;
  End;


procedure TForm13.Button2Click(Sender: TObject);
begin
ButtonCaption := Button2.Caption;
Buy;
end;

procedure TForm13.Button3Click(Sender: TObject);
begin
ButtonCaption := Button3.Caption;
Buy;
end;

end.

Thanks in advance

Reece

The code that reacts to pressing the buttons is not included here. Can you show an onclick event code for a button? The anser to uyour problem probalby is in the detail for how you are handling button clicks.

the button code is 499 to 503 and 505 to 509 the rest just repeat that but with the correct button name

OK, so it calls buy and sets a string variable, when you say theres more than one.. This description isnt clear..

That looks on face value an awful lot of repeated unnecessary code.
Can you do a picture of what your screen should look like?

yer sure i think this is what you meant i can't show it with the program running because the buttons will be invisible unless an item is entered that they can represent hope this helps.

also what i mean by there is more is that there is

procedure TForm13.Button4Click(Sender: TObject);
begin
ButtonCaption := Button4.Caption;
Buy;
end;

there is that section above pretty much repeated but the number in red is odviously different for every button that calls it

Have you traced the logic using debug and monitored the values for the local variables at each step? I am not sure what is not working when you press the button. If the first two buttons no longer work when the third one is added you need to set a breakppoint at the button click event code and follow its steps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.