U_szcx.pas
上传用户:psxgmh
上传日期:2013-04-08
资源大小:15112k
文件大小:4k
- unit U_szcx;
- interface
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Forms, Dialogs, Controls, StdCtrls,
- Buttons, ExtCtrls;
- type
- TfrmSzcx = class(TForm)
- Panel1: TPanel;
- SrcList: TListBox;
- IncludeBtn: TSpeedButton;
- IncAllBtn: TSpeedButton;
- ExcludeBtn: TSpeedButton;
- ExAllBtn: TSpeedButton;
- DstList: TListBox;
- Panel2: TPanel;
- SpeedButton1: TSpeedButton;
- SpeedButton2: TSpeedButton;
- procedure IncludeBtnClick(Sender: TObject);
- procedure ExcludeBtnClick(Sender: TObject);
- procedure IncAllBtnClick(Sender: TObject);
- procedure ExcAllBtnClick(Sender: TObject);
- procedure SpeedButton1Click(Sender: TObject);
- procedure FormActivate(Sender: TObject);
- procedure SpeedButton2Click(Sender: TObject);
- procedure SrcListDblClick(Sender: TObject);
- procedure DstListDblClick(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- procedure MoveSelected(List: TCustomListBox; Items: TStrings);
- procedure SetItem(List: TListBox; Index: Integer);
- function GetFirstSelection(List: TCustomListBox): Integer;
- procedure SetButtons;
- end;
- var
- frmSzcx: TfrmSzcx;
- Ordered: Boolean = False;
- implementation
- {$R *.DFM}
- procedure TfrmSzcx.IncludeBtnClick(Sender: TObject);
- var
- Index: Integer;
- begin
- Index := GetFirstSelection(SrcList);
- MoveSelected(SrcList, DstList.Items);
- SetItem(SrcList, Index);
- end;
- procedure TfrmSzcx.ExcludeBtnClick(Sender: TObject);
- var
- Index: Integer;
- begin
- Index := GetFirstSelection(DstList);
- MoveSelected(DstList, SrcList.Items);
- SetItem(DstList, Index);
- end;
- procedure TfrmSzcx.IncAllBtnClick(Sender: TObject);
- var
- I: Integer;
- begin
- for I := 0 to SrcList.Items.Count - 1 do
- DstList.Items.AddObject(SrcList.Items[I],
- SrcList.Items.Objects[I]);
- SrcList.Items.Clear;
- SetItem(SrcList, 0);
- end;
- procedure TfrmSzcx.ExcAllBtnClick(Sender: TObject);
- var
- I: Integer;
- begin
- for I := 0 to DstList.Items.Count - 1 do
- SrcList.Items.AddObject(DstList.Items[I], DstList.Items.Objects[I]);
- DstList.Items.Clear;
- SetItem(DstList, 0);
- end;
- procedure TfrmSzcx.MoveSelected(List: TCustomListBox; Items: TStrings);
- var
- I: Integer;
- begin
- for I := List.Items.Count - 1 downto 0 do
- if List.Selected[I] then
- begin
- Items.AddObject(List.Items[I], List.Items.Objects[I]);
- List.Items.Delete(I);
- end;
- end;
- procedure TfrmSzcx.SetButtons;
- var
- SrcEmpty, DstEmpty: Boolean;
- begin
- SrcEmpty := SrcList.Items.Count = 0;
- DstEmpty := DstList.Items.Count = 0;
- IncludeBtn.Enabled := not SrcEmpty;
- IncAllBtn.Enabled := not SrcEmpty;
- ExcludeBtn.Enabled := not DstEmpty;
- ExAllBtn.Enabled := not DstEmpty;
- end;
- function TfrmSzcx.GetFirstSelection(List: TCustomListBox): Integer;
- begin
- for Result := 0 to List.Items.Count - 1 do
- if List.Selected[Result] then Exit;
- Result := LB_ERR;
- end;
- procedure TfrmSzcx.SetItem(List: TListBox; Index: Integer);
- var
- MaxIndex: Integer;
- begin
- with List do
- begin
- SetFocus;
- MaxIndex := List.Items.Count - 1;
- if Index = LB_ERR then Index := 0
- else if Index > MaxIndex then Index := MaxIndex;
- Selected[Index] := True;
- end;
- SetButtons;
- end;
- procedure TfrmSzcx.SpeedButton1Click(Sender: TObject);
- begin
- Ordered := True;
- close;
- end;
- procedure TfrmSzcx.FormActivate(Sender: TObject);
- begin
- Ordered := False;
- end;
- procedure TfrmSzcx.SpeedButton2Click(Sender: TObject);
- begin
- close;
- end;
- procedure TfrmSzcx.SrcListDblClick(Sender: TObject);
- begin
- IncludeBtn.click;
- end;
- procedure TfrmSzcx.DstListDblClick(Sender: TObject);
- begin
- ExcludeBtn.click;
- end;
- end.