home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / tpw / docdemos / sbartest.pas < prev    next >
Pascal/Delphi Source File  |  1991-05-20  |  2KB  |  81 lines

  1. {************************************************}
  2. {                                                }
  3. {   Turbo Pascal for Windows                     }
  4. {   Demo program                                 }
  5. {   Copyright (c) 1991 by Borland International  }
  6. {                                                }
  7. {************************************************}
  8.  
  9. program SBarTest;
  10.  
  11. uses WObjects, WinTypes, WinProcs, Strings;
  12.          
  13. const
  14.   id_ThermScroll = 100;
  15.   id_Stat1 = 101;
  16.  
  17. type
  18.  
  19.   TestApplication = object(TApplication)
  20.     procedure InitMainWindow; virtual;
  21.   end;
  22.  
  23.   PTestWindow = ^TestWindow;
  24.  
  25.   TestWindow = object(TWindow)
  26.     ThermScroll : PScrollBar;
  27.     Stat1 : PStatic;
  28.     constructor Init(AParent: PWindowsObject; ATitle: PChar);
  29.     procedure SetupWindow; virtual;
  30.     procedure HandleThermScrollMsg(var Msg: TMessage);
  31.       virtual id_First + id_ThermScroll;
  32.   end;
  33.  
  34. { Set attributes and construct child controls }
  35. constructor TestWindow.Init(AParent: PWindowsObject; ATitle: PChar);
  36. begin
  37.   TWindow.Init(AParent, ATitle);
  38.   with Attr do
  39.   begin
  40.     X := 20;
  41.     Y := 20;
  42.     W := 380;
  43.     H := 250;
  44.   end;
  45.   ThermScroll := New(PScrollBar,
  46.     Init(@Self, id_ThermScroll, 20, 170, 340, 0, True));
  47.   Stat1 := New(PStatic,
  48.     Init(@Self, id_Stat1, ' 32 degrees', 135, 40, 160, 17, 0));
  49. end;
  50.  
  51. { Create scrollbar and static controls; set range of scrollbar }
  52. procedure TestWindow.SetupWindow;
  53. begin
  54.   TWindow.SetupWindow;
  55.   ThermScroll^.SetRange(32, 120);
  56. end;
  57.  
  58. { Handle notification messages from therm scrollbar }
  59. procedure TestWindow.HandleThermScrollMsg(var Msg: TMessage);
  60. var
  61.   cString: array[0..11] of Char;
  62. begin
  63.   Str(ThermScroll^.GetPosition:3, cString);
  64.   StrCat(cString, ' degrees');
  65.   Stat1^.SetText(cString);
  66. end;
  67.  
  68. procedure TestApplication.InitMainWindow;
  69. begin
  70.   MainWindow := New(PTestWindow, Init(nil, 'Thermostat'));
  71. end;
  72.  
  73. var
  74.   TestApp : TestApplication;
  75.  
  76. begin
  77.   TestApp.Init('SBarApp');
  78.   TestApp.Run;
  79.   TestApp.Done;
  80. end.
  81.