home *** CD-ROM | disk | FTP | other *** search
/ Delphi Programming Unleashed / Delphi_Programming_Unleashed_SAMS_Publishing_1995.iso / chap11 / addall / main.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-03-21  |  2.0 KB  |  97 lines

  1. unit Main;
  2.  
  3. { Program copyright (c) 1995 by Charles Calvert }
  4. { Project Name: ADDALL}
  5.  
  6. { Demonstrates:
  7.  
  8.     * Creating UNITS that contain utility routines
  9.     * Setting the PUT buttons Default property to True
  10.       to better handle hits on the Enter button.
  11.     * Assigning Hot keys to buttons with an Ampersand (&)
  12.  
  13. This program uses a utility unit called MATHBOX. It is stored
  14. in the UNITS subdirectory that ships with this book. Open
  15. up Options | Environment | Library and make sure the UNITS
  16. subdirectory is on your Library Path. }
  17.  
  18.  
  19. interface
  20.  
  21. uses
  22.   WinTypes, WinProcs,
  23.   Classes, Graphics,
  24.   Controls, Printers,
  25.   Forms, StdCtrls, ExtCtrls;
  26.  
  27. type
  28.   TForm1 = class(TForm)
  29.     ListBox1: TListBox;
  30.     Edit1: TEdit;
  31.     Label2: TLabel;
  32.     BPut: TButton;
  33.     BCalc: TButton;
  34.     Label1: TLabel;
  35.     BClose: TButton;
  36.     BClear: TButton;
  37.     Panel1: TPanel;
  38.     LResult: TLabel;
  39.     procedure BPutClick(Sender: TObject);
  40.     procedure BCalcClick(Sender: TObject);
  41.     procedure BCloseClick(Sender: TObject);
  42.     procedure BClearClick(Sender: TObject);
  43.     procedure ListBox1DblClick(Sender: TObject);
  44.     procedure FormCreate(Sender: TObject);
  45.   end;
  46.  
  47. var
  48.   Form1: TForm1;
  49.  
  50. implementation
  51.  
  52. uses
  53.   MathBox;
  54.  
  55. {$R *.DFM}
  56.  
  57. procedure TForm1.BPutClick(Sender: TObject);
  58. begin
  59.   ListBox1.Items.Add(Edit1.Text);
  60.   Edit1.Text := '';
  61.   Edit1.SetFocus;
  62. end;
  63.  
  64. procedure TForm1.BCalcClick(Sender: TObject);
  65. var
  66.   i: Integer;
  67.   Total: Real;
  68. begin
  69.   Total := 0;
  70.   for i := 0 to ListBox1.Items.Count - 1 do
  71.     Total :=  Total + Str2Real(ListBox1.Items.Strings[i]);
  72.   LResult.Caption := Real2Str(Total, 2, 2);
  73. end;
  74.  
  75. procedure TForm1.BCloseClick(Sender: TObject);
  76. begin
  77.   Close;
  78. end;
  79.  
  80. procedure TForm1.BClearClick(Sender: TObject);
  81. begin
  82.   ListBox1.Clear;
  83.   Edit1.SetFocus;
  84. end;
  85.  
  86. procedure TForm1.ListBox1DblClick(Sender: TObject);
  87. begin
  88.   ListBox1.Items.Delete(ListBox1.ItemIndex);
  89. end;
  90.  
  91. procedure TForm1.FormCreate(Sender: TObject);
  92. begin
  93.   Edit1.Text := '';
  94. end;
  95.  
  96. end.
  97.