home *** CD-ROM | disk | FTP | other *** search
/ Delphi Developer's Kit 1996 / Delphi Developer's Kit 1996.iso / power / picklist / testpick.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1995-12-22  |  3.7 KB  |  153 lines

  1. unit Testpick;
  2.  
  3. {Copyright 1995 by Robert Fabiszak
  4.   TESTPICK - Sample program to demonstate the usage and benefits
  5.   of the PICKLIST control.
  6.  
  7.   Free unrestricted use granted provided this copyright notice
  8.   is maintained.
  9.  
  10.   PICKLIST is an enhanced list box control for Borland's Delphi
  11.   product. Version 1.0. June, 1995}
  12.  
  13.  
  14. interface
  15.  
  16. uses
  17.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  18.   Forms, Dialogs, picklist, StdCtrls, ExtCtrls, Buttons, Spin;
  19.  
  20. type
  21.   TForm1 = class(TForm)
  22.     GroupBox1: TGroupBox;
  23.     TestLB: TPickList;
  24.     Label1: TLabel;
  25.     Panel1: TPanel;
  26.     Button1: TButton;
  27.     GroupBox2: TGroupBox;
  28.     PickList1: TPickList;
  29.     Label2: TLabel;
  30.     Panel2: TPanel;
  31.     GroupBox3: TGroupBox;
  32.     PickList2: TPickList;
  33.     BitBtn1: TBitBtn;
  34.     SpinEdit1: TSpinEdit;
  35.     Label4: TLabel;
  36.     Button2: TButton;
  37.     Button3: TButton;
  38.     BitBtn2: TBitBtn;
  39.     procedure FormCreate(Sender: TObject);
  40.     procedure Button1Click(Sender: TObject);
  41.     procedure PickList1Change(Sender: TObject);
  42.     procedure UpdatePanel1;
  43.     procedure UpdatePanel2;
  44.     procedure BitBtn1Click(Sender: TObject);
  45.     procedure SpinEdit1Change(Sender: TObject);
  46.     procedure Button2Click(Sender: TObject);
  47.     procedure Button3Click(Sender: TObject);
  48.     procedure BitBtn2Click(Sender: TObject);
  49.   private
  50.     { Private declarations }
  51.   public
  52.     { Public declarations }
  53.   end;
  54.  
  55. var
  56.   Form1: TForm1;
  57.  
  58. implementation
  59.  
  60. uses od_test;
  61.  
  62. {$R *.DFM}
  63.  
  64. procedure TForm1.FormCreate(Sender: TObject);
  65. begin
  66.   TestLB.Items.Add('Item 1');
  67.   TestLB.Items.Add('Item 2');
  68.   TestLB.Items.Add('Item 3');
  69.   PickList1.Items.Add('Test'#9'Row 1'#9'More');
  70.   PickList1.Items.Add('Test'#9'Row 2');
  71.   PickList1.Items.Add('Test'#9'Row 3');
  72.   UpdatePanel1;
  73.   UpdatePanel2;
  74.   SpinEdit1.Value := TestLB.Font.Size;
  75. end;
  76.  
  77. procedure TForm1.Button1Click(Sender: TObject);
  78. begin
  79.   if TestLB.SelectedStyle = psStandard then
  80.     MessageDlg('Changing from the standard Windows listbox to ' +
  81.       'owner-draw or changing font size will remove any selections.', mtInformation, [mbOK], 0);
  82.  
  83.   {presssing the button will cycle through the two built-in
  84.   owner draw formats}
  85.   with TestLB do
  86.     if SelectedStyle = psBoldText then
  87.       SelectedStyle := psCheckbox
  88.     else
  89.       SelectedStyle := psBoldText;
  90.   UpdatePanel1;
  91. end;
  92.  
  93. procedure TForm1.UpdatePanel1;
  94. const
  95.   LBStr: array[TSelectedStyle] of string = ('psStandard', 'psCheckbox',
  96.     'psBoldText', 'psOwnerDraw');
  97. begin
  98.   Panel1.Caption := LBStr[TestLB.SelectedStyle];
  99.   TestLB.Hint := 'Current style: ' + LBStr[TestLB.SelectedStyle];
  100. end;
  101.  
  102.  
  103. procedure TForm1.PickList1Change(Sender: TObject);
  104. begin
  105.   {a simple method to demonstrate the OnClick event handler}
  106.   MessageDlg('Processing Change Method; current selection = ' +
  107.     IntToStr(PickList1.ItemIndex), mtCustom, [mbOK], 0);
  108.   UpdatePanel2;
  109. end;
  110.  
  111.  
  112. procedure TForm1.UpdatePanel2;
  113. begin
  114.   if PickList1.ItemIndex >= 0 then
  115.     Panel2.Caption := PickList1.Items[PickList1.ItemIndex]
  116.   else
  117.     Panel2.Caption := 'no item selected';
  118. end;
  119.  
  120.  
  121. procedure TForm1.BitBtn1Click(Sender: TObject);
  122. begin
  123.   Close;
  124. end;
  125.  
  126. procedure TForm1.SpinEdit1Change(Sender: TObject);
  127. begin
  128.   {this demonstrates how the graphic will automatically
  129.   resize to match the listbox font size}
  130.   TestLB.Font.Size := SpinEdit1.Value;
  131.  
  132.   {keep the item height at about the same ratio as original}
  133.   TestLB.ItemHeight := (14 * TestLB.Font.Size) div 8;
  134. end;
  135.  
  136. procedure TForm1.Button2Click(Sender: TObject);
  137. begin
  138.   PickList2.SelectAll;
  139. end;
  140.  
  141. procedure TForm1.Button3Click(Sender: TObject);
  142. begin
  143.   PickList2.ClearSelection;
  144. end;
  145.  
  146.  
  147. procedure TForm1.BitBtn2Click(Sender: TObject);
  148. begin
  149.   PoemDialog.ShowModal;
  150. end;
  151.  
  152. end.
  153.