无法调用TXSpaceMutiSelectComboBox.DeSelectAll( Sender: TObject )的故障。(100)

  • 主题发起人 主题发起人 zwker
  • 开始时间 开始时间
Z

zwker

Unregistered / Unconfirmed
GUEST, unregistred user!
TXSpaceMutiSelectComboBox.DeSelectAll( Sender: TObject )的作用是取消选择的钩钩,控件本身可以右键全部不选,我就想在程序里调用此过程。调用MyXSpaceMutiSelectComboBox.DeSelectAll(MyXSpaceMutiSelectComboBox),无法实现取消选择的项目。小钩钩还在勾着。unit XSpaceMutiSelectComboBox;interfaceuses Windows, Messages, SysUtils, Classes, Controls, StdCtrls, Graphics, Forms, Menus, CheckLst;const Horizontal_ScrollBar = 20;type TXSpaceMutiSelectComboBox = class(TComboBox) private FDDForm : TForm; FListBox : TCheckListBox; FPopup: TPopupMenu;// FSelectList: TStrings; FSelectAll: TMenuItem; FSplitterFlag: String; FDeSelectAll: TMenuItem; FHorzScrollBar : boolean; FSelectIndex: TStrings; procedure OwnerDrawCheck ( Index: integer ); procedure OwnerDrawRect ( Index: integer ); procedure Toggle( Index : integer ); function IfChecked( Index: integer ) : boolean; function GetBeforeFlagString(Str, Flag: String): String; procedure SelectIndex(); protected procedure DropDown; override; public constructor Create ( AOwner : TComponent ); override; destructor Destroy; override; procedure ClosePopUp( Sender : TObject ); procedure ListBoxDrawItem( Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState ); procedure ListBoxMouseDown( Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer ); function SelectedList : TStringList; function NonSelectedList : TStringList; function SelectedString : string; procedure SelectAll( Sender: TObject ); reintroduce; procedure DeSelectAll( Sender: TObject ); procedure Checked( Index: integer ); procedure UnChecked( Index: integer ); function IsChecked ( Index: integer ) : boolean; procedure CheckAll; procedure UnCheckAll; published property HorzScrollBar : boolean read FHorzScrollBar write FHorzScrollBar default false;// property SelectList: TStringList read SelectedList;// write FSelectList; property SplitterFlag: String read FSplitterFlag write FSplitterFlag; end;procedure Register;implementation{ TXSpaceMutiSelectComboBox }constructor TXSpaceMutiSelectComboBox.Create ( AOwner : TComponent );begin inherited Create( AOwner ); // Creat PopUp List FDDForm := TForm.Create( self ); // Create SelectList// FSelectList:=TStringList.Create; // Create SelectIndex FSelectIndex:=TStringList.Create; // Create ListBox FListBox := TCheckListBox.Create( FDDForm ); FListBox.Parent := FDDForm; FListBox.Align := alClient; FListBox.BorderStyle:= bsNone; FListBox.BevelKind:= bkFlat;// FListBox.Style := lbOwnerDrawFixed;// FListBox.OnDrawItem := ListBoxDrawItem; FListBox.OnMouseDown := ListBoxMouseDown; // Create PopUp FPopUp := TPopupMenu.Create( FListBox ); FSelectAll := TMenuItem.Create( FPopUp ); FSelectAll.Caption := '&S全部选中'; FDeSelectAll := TMenuItem.Create( FPopUp ); FDeSelectAll.Caption := '&D取消所有选中'; FPopUp.Items.Insert( 0, FSelectAll ); FPopUp.Items.Insert( 1, FDeSelectAll ); FSelectAll.OnClick := SelectAll; FDeSelectAll.OnClick := DeSelectAll; FListBox.PopupMenu := FPopUp; // Init SplitterFlag FSplitterFlag:=#32;end;destructor TXSpaceMutiSelectComboBox.Destroy;begin FSelectAll.Free; FDeSelectAll.Free; FPopup.Free; FListBox.Free; FDDForm.Free;// FSelectList.Free; inherited Destroy;end;procedure TXSpaceMutiSelectComboBox.DropDown;var ScreenPoint : TPoint; nDropDown, i : integer;begin Inherited; if ( DropDownCount <= Items.Count ) then nDropDown := DropDownCount else nDropDown := Items.Count; // Assign Form coordinate and show ScreenPoint := Parent.ClientToScreen( Point( self.Left, self.Top+self.Height ) ); FListBox.Font := self.Font; FListBox.Color := self.Color; FListBox.ItemHeight := self.ItemHeight; FListBox.Items.Assign( Items ); with FDDForm do begin Font := self.Font; Left := ScreenPoint.X; Top := ScreenPoint.Y; Width := self.Width; Height := ( nDropDown * self.ItemHeight ) + 5; if FHorzScrollBar then Height := Height + Horizontal_ScrollBar; Color := clAqua; BorderStyle := bsNone; OnDeactivate := ClosePopUp; end; if FHorzScrollBar then SendMessage(FListbox.Handle, LB_SetHorizontalExtent, 1000, Longint(0)); FDDForm.Show; for i:=0 to FSelectIndex.Count-1 do FListBox.Checked[StrToInt(FSelectIndex.Strings)]:= True;end;procedure TXSpaceMutiSelectComboBox.ClosePopUp( Sender : TObject );begin Items.Assign( FListBox.Items ); SelectIndex; Text := SelectedString; (Sender as TForm).Close;end;procedure TXSpaceMutiSelectComboBox.OwnerDrawCheck ( Index: integer );var Rect : TRect; FontHeight : integer;begin FontHeight := FListBox.ItemHeight - 1; Rect := FListBox.ItemRect( Index ); with FListBox.Canvas, Rect do begin MoveTo( Left+1, Top+1 ); LineTo( Left+FontHeight , Top+FontHeight ); MoveTo( Left+1, Top+FontHeight-1 ); LineTo( Left+FontHeight , Top ); end;end;procedure TXSpaceMutiSelectComboBox.OwnerDrawRect ( Index: integer );var Rect : TRect; FontHeight : integer;begin FontHeight := FListBox.ItemHeight - 1; Rect := FListBox.ItemRect( Index ); with FListBox.Canvas, Rect do begin FillRect( Rect ); Rectangle( Left+1, Top+1, Left+FontHeight, Top+FontHeight); TextOut( Left+FontHeight+3, Top, FListBox.Items[Index] ); end;end;procedure TXSpaceMutiSelectComboBox.Toggle( Index : integer );begin with FListBox do begin if FListBox.Checked[Index] then //if ( Items.objects[ Index ] = pointer(1) ) then FListBox.Checked[Index]:= False //Items.objects[ Index ] := pointer(0) else FListBox.Checked[Index]:= True; //Items.objects[ Index ] := pointer(1); Refresh; end;end;procedure TXSpaceMutiSelectComboBox.ListBoxDrawItem( Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState );begin if IfChecked( Index ) then begin OwnerDrawRect( Index ); OwnerDrawCheck( Index ); end else OwnerDrawRect( Index );end;procedure TXSpaceMutiSelectComboBox.ListBoxMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);begin if (Sender As TCheckListBox).ItemIndex = -1 then exit; Toggle( (Sender As TCheckListBox).ItemIndex );end;function TXSpaceMutiSelectComboBox.SelectedList : TStringList;var nCount, i : integer;begin result := TStringList.Create; nCount := Items.Count-1; for i := 0 to nCount do if FListBox.Checked then //if Items.Objects[ i ] = pointer(1) then result.Add( GetBeforeFlagString(Trim(Items[ i ]),FSplitterFlag) );end;function TXSpaceMutiSelectComboBox.NonSelectedList : TStringList;var nCount, i : integer;begin result := TStringList.Create; nCount := Items.Count-1; for i := 0 to nCount do if Not FListBox.Checked then //if Items.Objects[ i ] = pointer(0) then result.Add( GetBeforeFlagString(Trim(Items[ i ]),FSplitterFlag) );end;function TXSpaceMutiSelectComboBox.SelectedString : string;var i : integer;begin result := '';// FSelectList.Clear; with FListBox do for i := 0 to Items.Count-1 do if FListBox.Checked then //if Items.Objects[ i ] = pointer(1) then begin// FSelectList.Add(GetBeforeFlagString(Trim(Items[ i ]),FSplitterFlag)); result := result + GetBeforeFlagString(Trim(Items[ i ]),FSplitterFlag) + ',';//Trim(Items[ i ]) + ','; end; if ( result <> '' ) then result := copy( result, 0, Length(result)-1 );end;//procedure TXSpaceMutiSelectComboBox.SelectAll( Sender: TObject );procedure TXSpaceMutiSelectComboBox.SelectAll;var i : integer;begin with FListBox do begin for i := 0 to Items.Count-1 do FListBox.Checked:= True; //Items.objects[ i ] := pointer(1); refresh; end;end;procedure TXSpaceMutiSelectComboBox.DeSelectAll( Sender: TObject );var i : integer;begin with FListBox do begin for i := 0 to Items.Count-1 do FListBox.Checked:= False; //Items.objects[ i ] := pointer(0); refresh; end;end;function TXSpaceMutiSelectComboBox.IsChecked( Index: integer ) : boolean;begin result:= FListBox.Checked[Index]; //result := Items.Objects[ Index ] = pointer(1);end;function TXSpaceMutiSelectComboBox.IfChecked( Index: integer ) : boolean;begin with FListBox do begin if FListBox.Checked[index] then //if Items.Objects[ Index ] = pointer(1) then result := True else result := False; end;end;procedure TXSpaceMutiSelectComboBox.Checked ( index : integer );begin if ( index >= 0 ) and ( index <= Items.Count ) then FListBox.Checked[index]:= True; //Items.Objects[ index ] := Pointer(1);end;procedure TXSpaceMutiSelectComboBox.UnChecked ( index : integer );begin if ( index >= 0 ) and ( index <= Items.Count ) then FListBox.Checked[index]:= False; //Items.Objects[ index ] := Pointer(0);end;procedure TXSpaceMutiSelectComboBox.CheckAll;var i: integer;begin for i := 0 to Items.Count-1 do //Items.Objects[ i ] := Pointer(1); FListBox.Checked:=True;end;procedure TXSpaceMutiSelectComboBox.UnCheckAll;var i: integer;begin with FListBox do begin for i := 0 to Items.Count-1 do FListBox.Checked:= False; end; //Items.Objects[ i ] := Pointer(0);end;function TXSpaceMutiSelectComboBox.GetBeforeFlagString(Str, Flag: String): String;var i: Integer;begin i:=Pos(Flag, Str); if i>0 then begin Result:= Copy(Str, 1, i-1); end else Result:= Str;end;procedure TXSpaceMutiSelectComboBox.SelectIndex;var i: Integer;begin FSelectIndex.Clear; for i:= 0 to FListBox.Items.Count-1 do if FListBox.Checked then FSelectIndex.Add(IntToStr(i));end;procedure Register;begin RegisterComponents('XSpace', [TXSpaceMutiSelectComboBox]);end;end.
 
调用控件的过程,是不是我用的sender有误导致,控件本身这个功能能用的。
 
有哪位老大帮忙看一下?谢谢。
 

Similar threads

S
回复
0
查看
896
SUNSTONE的Delphi笔记
S
S
回复
0
查看
873
SUNSTONE的Delphi笔记
S
S
回复
0
查看
688
SUNSTONE的Delphi笔记
S
S
回复
0
查看
683
SUNSTONE的Delphi笔记
S
后退
顶部