procedure TForm1.ListBox1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState;
var Accept: Boolean);
begin
Accept := (Sender = Source)
and (Sender = ListBox1);
end;
procedure TForm1.ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);
var
I, NewPos: Integer;
Temp: TStringList;
begin
if not (Sender = Source)
and (Sender = ListBox1)
then
Exit;
Temp := TStringList.Create;
try
NewPos := ListBox1.ItemAtPos(Point(X, Y), True);
for I := Pred(ListBox1.Items.Count)
downto 0
do
if ListBox1.Selected[I]
then
begin
Temp.Insert(0, ListBox1.Items[I]);
ListBox1.Items.Delete(I);
if I < NewPos
then
Dec(NewPos);
end;
if NewPos < 0
then
ListBox1.Items.AddStrings(Temp)
else for I := Pred(Temp.Count)
downto 0
do
ListBox1.Items.Insert(NewPos, Temp[I]);
finally
Temp.Free;
end;
end;