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);
Application.ProcessMessages;
end;
if NewPos < 0
then
begin
for I := 0
to Pred(Temp.Count)
do
begin
ListBox1.Items.Add(Temp[I]);
Application.ProcessMessages;
end;
end else begin
for I := Pred(Temp.Count)
downto 0
do
begin
ListBox1.Items.Insert(NewPos, Temp[I]);
Application.ProcessMessages;
end;
end;
finally
Temp.Free;
end;
end;