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

  1. {************************************************}
  2. {                                                }
  3. {   Turbo Pascal for Windows                     }
  4. {   Demo program                                 }
  5. {   Copyright (c) 1991 by Borland International  }
  6. {                                                }
  7. {************************************************}
  8.  
  9. program InitResTest;
  10.  
  11. uses WObjects, WinTypes, WinProcs;
  12.  
  13. const
  14.   id_LB1 = 101;
  15.  
  16. type
  17.   TestApplication = object(TApplication)
  18.     procedure InitMainWindow; virtual;
  19.   end;
  20.  
  21.   PTestWindow = ^TestWindow;
  22.  
  23.   TestWindow = object(TWindow)
  24.     LB1: PListBox;
  25.     constructor Init(AParent: PWindowsObject; ATitle: PChar);
  26.     procedure SetupWindow; virtual;
  27.     procedure HandleListBoxMsg(var Msg: TMessage);
  28.       virtual id_First + id_LB1;
  29.   end;
  30.  
  31. { --------TestWindow methods------------------ }
  32. constructor TestWindow.Init(AParent: PWindowsObject; ATitle: PChar);
  33. begin
  34.   TWindow.Init(AParent, ATitle);
  35.   LB1 := new(PListBox, Init(@Self, id_LB1, 20, 20, 340, 100));
  36. end;
  37.  
  38. procedure TestWindow.SetupWindow;
  39. begin
  40.   TWindow.SetupWindow;
  41.   LB1^.AddString('Item 1');
  42.   LB1^.AddString('Item 2');
  43.   LB1^.AddString('Item 3');
  44.   LB1^.InsertString('Item 1.5', 1);
  45.   LB1^.AddString('Item 4');
  46.   LB1^.AddString('Item 5');
  47.   LB1^.AddString('Item 6');
  48. end;
  49.  
  50. procedure TestWindow.HandleListBoxMsg(var Msg: TMessage);
  51. var
  52.   Idx     : Integer;
  53.   ItemText: array[0..10] of Char;
  54. begin
  55.   if Msg.LParamHi = lbn_SelChange then
  56.   begin
  57.     Idx := LB1^.GetSelIndex;
  58.     if LB1^.GetStringLen(Idx) < 11 then
  59.     begin
  60.       LB1^.GetSelString(ItemText, 10);
  61.       MessageBox(HWindow, ItemText, 'You selected:', mb_OK);
  62.     end;
  63.   end
  64.   else DefWndProc(Msg);
  65. end;
  66.  
  67. { -----------TestApplication Methods------------ }
  68. procedure TestApplication.InitMainWindow;
  69. begin
  70.   MainWindow := New(PTestWindow, Init(nil, 'List Box Tester'));
  71. end;
  72.  
  73. var
  74.   TestApp : TestApplication;
  75.  
  76. begin
  77.   TestApp.Init('LBoxTest');
  78.   TestApp.Run;
  79.   TestApp.Done;
  80. end.
  81.  
  82.