Before writing code, always make the main unit full brim; Now more like the control more independent function as a unit, overwriting properties, overloaded methods ... Even if only a little bit and the default is different, also like to be independent. Just use the Tlistbox, you need to be able to drag elements, double-click Delete.
Unit ListBox2;
Interfaceuses
system.classes, Vcl.controls, Vcl.stdctrls, system.types;
Type
TListBox2 = Class (Tcustomlistbox)
protectedprocedure DragOver (source:tobject; X:integer; Y:integer; State:tdragstate; var
accept:boolean); Override;procedure DblClick; Override;
Publicconstructor Create (aowner:tcomponent); Override;procedure DragDrop (source:tobject; X:
Integer; Y:integer); Override;
End;
implementation{TListBox2}constructor tlistbox2.create (aowner:tcomponent);
Begin
inherited;
DragMode: = dmautomatic;
End;
Procedure Tlistbox2.dblclick;
Begin
inherited;
Items.delete (itemindex);
End;
Procedure Tlistbox2.dragdrop (Source:tobject; X, Y:integer);
Begin
inherited;
Items.exchange (ItemIndex, Itematpos (Point (X,y), True);
End;
Procedure Tlistbox2.dragover (Source:tobject; X, Y:integer; State:tdragstate; var Accept:
Boolean);
Begin
inherited;
Accept: = True;
End;
End.
Test:
Uses ListBox2;
Procedure Tform1.formcreate (sender:tobject);
Begin with
tlistbox2.create (self) dobeginparent: = self;
Align: = Alleft;
Items.commatext: = ' a,b,c,d,e,f,g ';
End;
End