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

  1. {************************************************}
  2. {                                                }
  3. {   Turbo Pascal for Windows                     }
  4. {   Demo program                                 }
  5. {   Copyright (c) 1991 by Borland International  }
  6. {                                                }
  7. {************************************************}
  8.  
  9. program LBoxTest;
  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. constructor TestWindow.Init(AParent: PWindowsObject; ATitle: PChar);
  32. begin
  33.   TWindow.Init(AParent, ATitle);
  34.   LB1 := New(PListBox, Init(@Self, id_LB1, 20, 20, 340, 100));
  35. end;
  36.  
  37. procedure TestWindow.SetupWindow;
  38. begin
  39.   TWindow.SetupWindow;
  40.   LB1^.AddString('Item 1');
  41.   LB1^.AddString('Item 2');
  42.   LB1^.AddString('Item 3');
  43.   LB1^.InsertString('Item 1.5', 1);
  44.   LB1^.AddString('Item 4');
  45.   LB1^.AddString('Item 5');
  46.   LB1^.AddString('Item 6');
  47. end;
  48.  
  49. procedure TestWindow.HandleListBoxMsg(var Msg: TMessage);
  50. var
  51.   Idx: Integer;
  52.   ItemText: array[0..10] of Char;
  53. begin
  54.   if Msg.LParamHi = lbn_SelChange then
  55.   begin
  56.     Idx := LB1^.GetSelIndex;
  57.     if LB1^.GetStringLen(Idx) < SizeOf(ItemText) then
  58.     begin
  59.       LB1^.GetSelString(ItemText, 10);
  60.       MessageBox(HWindow, ItemText, 'You selected:', mb_OK);
  61.     end;
  62.   end
  63.   else DefWndProc(Msg);
  64. end;
  65.  
  66. procedure TestApplication.InitMainWindow;
  67. begin
  68.   MainWindow := New(PTestWindow, Init(nil, 'List Box Tester'));
  69. end;
  70.  
  71. var
  72.   TestApp : TestApplication;
  73.  
  74. begin
  75.   TestApp.Init('LBoxTest');
  76.   TestApp.Run;
  77.   TestApp.Done;
  78. end.
  79.  
  80.