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

  1. unit Main;
  2.  
  3. { Program copyright (c) 1994 by Charles Calvert }
  4. { Project Name: TWOPOW2 }
  5.  
  6. { This program demonstrates:
  7.  
  8.     * using for loops.
  9.  
  10.     * Setting a Default button for automatically responding
  11.       to a press on the enter key.
  12.  
  13.     * Reporting errors when the user enters invalid data. 
  14. }
  15.  
  16.  
  17. interface
  18.  
  19. uses
  20.   WinTypes, WinProcs,
  21.   Classes, Graphics,
  22.   Controls, StdCtrls,
  23.   Printers, Forms, SysUtils, ExtCtrls;
  24.  
  25. type
  26.   TForm1 = class(TForm)
  27.     BCalc: TButton;
  28.     Edit1: TEdit;
  29.     Panel1: TPanel;
  30.     Panel2: TPanel;
  31.     Panel3: TPanel;
  32.     procedure BCalcClick(Sender: TObject);
  33.     procedure FormCreate(Sender: TObject);
  34.   end;
  35.  
  36. var
  37.   Form1: TForm1;
  38.  
  39. implementation
  40.  
  41. {$R *.DFM}
  42.  
  43. procedure TForm1.BCalcClick(Sender: TObject);
  44. var
  45.   i, j, k: LongInt;
  46. begin
  47.   k := 1;
  48.   j := StrToInt(Edit1.Text);
  49.   if J > 30 then begin
  50.     Panel2.Caption := 'Power too high';
  51.     Exit;
  52.   end;
  53.   for i := 1 to j do
  54.     k := k * 2;
  55.   Panel2.Caption := IntToStr(k);
  56. end;
  57.  
  58. procedure TForm1.FormCreate(Sender: TObject);
  59. begin
  60.   Edit1.Text := '';
  61. end;
  62.  
  63. end.
  64.