Delphi速選組件
{*******************************************************}
{ }
{ 速選組件 }
{ }
{ 版權所有 (C) 2015.5 hbfan }
{ }
{*******************************************************}
unit FastSelect;
interface
uses
Classes, Controls, StdCtrls, CheckLst;
type
TFASTSELECT = class(TComponent)
private
FSelectAllRaiseObject: TwinControl;
FSelectClearRaiseObject: TwinControl;
FSelectionSource: TwinControl;
FSelectReversedRaiseObject: TwinControl;
procedure SetSelectAllRaiseObject(const Value: TwinControl);
procedure SetSelectClearRaiseObject(const Value: TwinControl);
procedure SetSelectReversedRaiseObject(const Value: TwinControl);
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
// 全選
procedure OnSelectedAll(sender: Tobject);
// 清空
procedure OnSelectedClear(sender: Tobject);
published
{ Published declarations }
// 全選組件
property SelectAllRaiseObject: TwinControl read FSelectAllRaiseObject write
SetSelectAllRaiseObject;
// 清空組件
property SelectClearRaiseObject: TwinControl read FSelectClearRaiseObject write
SetSelectClearRaiseObject;
// 反選組件
property SelectReversedRaiseObject: TwinControl read FSelectReversedRaiseObject
write SetSelectReversedRaiseObject;
// 數據源組件
property SelectionSource: TwinControl read FSelectionSource write
FSelectionSource;
end;
procedure Register;
implementation
{$R *.dcr}
procedure Register;
begin
RegisterComponents('hbfan', [TFastSelect]);
end;
procedure TFastSelect.OnSelectedAll(sender: Tobject);
var
i: integer;
FSourceListBox: TcheckListBox;
begin
if FSelectionSource is TcheckListBox then
begin
FSourceListBox := (FselectionSource as TcheckListBox);
for i := 0 to FSourceListBox.Count - 1 do
FsourceListBox.Checked[i] := true;
end;
end;
procedure TFastSelect.OnSelectedClear(sender: Tobject);
var
i: integer;
FSourceListBox: TcheckListBox;
begin
if FSelectionSource is TcheckListBox then
begin
FSourceListBox := (FselectionSource as TcheckListBox);
for i := 0 to FSourceListBox.Count - 1 do
FsourceListBox.Checked[i] := false;
end;
end;
procedure TFastSelect.SetSelectAllRaiseObject(const Value: TwinControl);
begin
FSelectAllRaiseObject := Value;
if Value is Tbutton then
begin
(value as Tbutton).Caption := '全選';
(value as Tbutton).OnClick := OnSelectedAll;
end;
end;
procedure TFastSelect.SetSelectClearRaiseObject(const Value: TwinControl);
begin
FSelectClearRaiseObject := Value;
if Value is Tbutton then
begin
(value as Tbutton).Caption := '清空';
(value as Tbutton).OnClick := OnSelectedClear;
end;
end;
procedure TFastSelect.SetSelectReversedRaiseObject(
const Value: TwinControl);
begin
FSelectReversedRaiseObject := Value;
if Value is Tbutton then
begin
(value as Tbutton).Caption := '反選';
(value as Tbutton).OnClick := OnSelectedReversed;
end;
end;
end.