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

  1. unit Main;
  2.  
  3. { Program copyright (c) 1994 by Charles Calvert }
  4. { Project Name: TWOPOW }
  5.  
  6. { This program shows:
  7.  
  8.      * How to create For loops.
  9.  
  10.      * How to raise an integer to
  11.        particular power.
  12.  
  13.   Note that you can fairly easily max this program
  14.   out by asking to raising 2 to a power that produces
  15.   a result larger than can be held in a LongInt:
  16.   High(ALongInt). 2 ^ 30 is the most it will
  17.   handle. Try entering 31 while setting OverFlow checking
  18.   on or off by placing or removing the $ before the Q
  19.   shown below. }
  20.  
  21. {$Q+}
  22.  
  23. interface
  24.  
  25. uses
  26.   WinTypes, WinProcs, SysUtils,
  27.   Classes, Graphics, StdCtrls,
  28.   Controls, Printers, Forms;
  29.  
  30. type
  31.   TForm1 = class(TForm)
  32.     BCalc: TButton;
  33.     Label1: TLabel;
  34.     Edit1: TEdit;
  35.     Label2: TLabel;
  36.     ListBox1: TListBox;
  37.     Label3: TLabel;
  38.     procedure BCalcClick(Sender: TObject);
  39.   end;
  40.  
  41. var
  42.   Form1: TForm1;
  43.  
  44. implementation
  45.  
  46. {$R *.DFM}
  47.  
  48. procedure TForm1.BCalcClick(Sender: TObject);
  49. var
  50.   i, j, k: LongInt;
  51. begin
  52.   ListBox1.Clear;
  53.   k := 1;
  54.   j := StrToInt(Edit1.Text);
  55.   for i := 1 to j do begin
  56.     k := k * 2;
  57.     ListBox1.Items.Add(IntToStr(k));
  58.   end;
  59.   Label1.Caption := IntToStr(k);
  60. end; 
  61.  
  62. end.
  63.