home *** CD-ROM | disk | FTP | other *** search
/ Delphi 4 Bible / Delphi_4_Bible_Tom_Swan_IDG_Books_1998.iso / source / UpDownDemo / Main.pas < prev    next >
Pascal/Delphi Source File  |  1998-02-28  |  2KB  |  67 lines

  1. unit Main;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls, Spin, ComCtrls, Buttons;
  8.  
  9. type
  10.   TMainForm = class(TForm)
  11.     UpDown1: TUpDown;
  12.     SpinButton1: TSpinButton;
  13.     Label1: TLabel;
  14.     Label2: TLabel;
  15.     BitBtn1: TBitBtn;
  16.     StaticText1: TStaticText;
  17.     StaticText2: TStaticText;
  18.     procedure SpinButton1UpClick(Sender: TObject);
  19.     procedure SpinButton1DownClick(Sender: TObject);
  20.   private
  21.     { Private declarations }
  22.   public
  23.     { Public declarations }
  24.   end;
  25.  
  26. var
  27.   MainForm: TMainForm;
  28.  
  29. implementation
  30.  
  31. {$R *.DFM}
  32.  
  33. { These constants and the two event handlers are needed
  34.   by SpinButton components to associate them with another
  35.   control, a StaticText object in this demonstration. The
  36.   new UpDown component needs none of this programming because
  37.   it can be automatically associated with another control. }
  38. const
  39.   Min = -10;
  40.   Max = +10;
  41.  
  42. { Respond to user clicking the SpinButton's Up button }
  43. procedure TMainForm.SpinButton1UpClick(Sender: TObject);
  44. var
  45.   V: Integer;
  46. begin
  47.   V := StrToInt(StaticText2.Caption);
  48.   if V = Max
  49.     then V := Min
  50.     else inc(V);
  51.   StaticText2.Caption := IntToStr(V);
  52. end;
  53.  
  54. { Respond to user clicking the SpinButton's Down button }
  55. procedure TMainForm.SpinButton1DownClick(Sender: TObject);
  56. var
  57.   V: Integer;
  58. begin
  59.   V := StrToInt(StaticText2.Caption);
  60.   if V = Min
  61.     then V := Max
  62.     else dec(V);
  63.   StaticText2.Caption := IntToStr(V);
  64. end;
  65.  
  66. end.
  67.