home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l040 / 11.ddi / WDOCDEMO.ZIP / LBOXTEST.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-10-27  |  1.9 KB  |  79 lines

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