home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1996 August / VPR9608A.BIN / del20try / install / data.z / DUALLIST.PAS < prev    next >
Pascal/Delphi Source File  |  1996-05-08  |  3KB  |  128 lines

  1. unit DualList;
  2.  
  3. interface
  4.  
  5. uses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls, 
  6.   Buttons;
  7.  
  8. type
  9.   TDualListDlg = class(TForm)
  10.     OKBtn: TButton;
  11.     CancelBtn: TButton;
  12.     HelpBtn: TButton;
  13.     SrcList: TListBox;
  14.     DstList: TListBox;
  15.     SrcLabel: TLabel;
  16.     DstLabel: TLabel;
  17.     IncludeBtn: TSpeedButton;
  18.     IncAllBtn: TSpeedButton;
  19.     ExcludeBtn: TSpeedButton;
  20.     ExAllBtn: TSpeedButton;
  21.     procedure IncludeBtnClick(Sender: TObject);
  22.     procedure ExcludeBtnClick(Sender: TObject);
  23.     procedure IncAllBtnClick(Sender: TObject);
  24.     procedure ExcAllBtnClick(Sender: TObject);
  25.     procedure MoveSelected(List: TCustomListBox; Items: TStrings);
  26.     procedure SetItem(List: TListBox; Index: Integer);
  27.     function GetFirstSelection(List: TCustomListBox): Integer;
  28.     procedure SetButtons;
  29.   private
  30.     { Private declarations }
  31.   public
  32.     { Public declarations }
  33.   end;
  34.  
  35. var
  36.   DualListDlg: TDualListDlg;
  37.  
  38. implementation
  39.  
  40. {$R *.DFM}
  41.  
  42. procedure TDualListDlg.IncludeBtnClick(Sender: TObject);
  43. var
  44.   Index: Integer;
  45. begin
  46.   Index := GetFirstSelection(SrcList);
  47.   MoveSelected(SrcList, DstList.Items);
  48.   SetItem(SrcList, Index);
  49. end;
  50.  
  51. procedure TDualListDlg.ExcludeBtnClick(Sender: TObject);
  52. var
  53.   Index: Integer;
  54. begin
  55.   Index := GetFirstSelection(DstList);
  56.   MoveSelected(DstList, SrcList.Items);
  57.   SetItem(DstList, Index);
  58. end;
  59.  
  60. procedure TDualListDlg.IncAllBtnClick(Sender: TObject);
  61. var
  62.   I: Integer;
  63. begin
  64.   for I := 0 to SrcList.Items.Count - 1 do
  65.     DstList.Items.AddObject(SrcList.Items[I], 
  66.       SrcList.Items.Objects[I]);
  67.   SrcList.Items.Clear;
  68.   SetItem(SrcList, 0);
  69. end;
  70.  
  71. procedure TDualListDlg.ExcAllBtnClick(Sender: TObject);
  72. var
  73.   I: Integer;
  74. begin
  75.   for I := 0 to DstList.Items.Count - 1 do
  76.     SrcList.Items.AddObject(DstList.Items[I], DstList.Items.Objects[I]);
  77.   DstList.Items.Clear;
  78.   SetItem(DstList, 0);
  79. end;
  80.  
  81. procedure TDualListDlg.MoveSelected(List: TCustomListBox; Items: TStrings);
  82. var
  83.   I: Integer;
  84. begin
  85.   for I := List.Items.Count - 1 downto 0 do
  86.     if List.Selected[I] then
  87.     begin
  88.       Items.AddObject(List.Items[I], List.Items.Objects[I]);
  89.       List.Items.Delete(I);
  90.     end;
  91. end;
  92.  
  93. procedure TDualListDlg.SetButtons;
  94. var
  95.   SrcEmpty, DstEmpty: Boolean;
  96. begin
  97.   SrcEmpty := SrcList.Items.Count = 0;
  98.   DstEmpty := DstList.Items.Count = 0;
  99.   IncludeBtn.Enabled := not SrcEmpty;
  100.   IncAllBtn.Enabled := not SrcEmpty;
  101.   ExcludeBtn.Enabled := not DstEmpty;
  102.   ExAllBtn.Enabled := not DstEmpty;
  103. end;
  104.  
  105. function TDualListDlg.GetFirstSelection(List: TCustomListBox): Integer;
  106. begin
  107.   for Result := 0 to List.Items.Count - 1 do
  108.     if List.Selected[Result] then Exit;
  109.   Result := LB_ERR;
  110. end;
  111.  
  112. procedure TDualListDlg.SetItem(List: TListBox; Index: Integer);
  113. var
  114.   MaxIndex: Integer;
  115. begin
  116.   with List do
  117.   begin
  118.     SetFocus;
  119.     MaxIndex := List.Items.Count - 1;
  120.     if Index = LB_ERR then Index := 0
  121.     else if Index > MaxIndex then Index := MaxIndex;
  122.     Selected[Index] := True;
  123.   end;
  124.   SetButtons;
  125. end;
  126.  
  127. end.
  128.