Drag and Drop over TCustomItem

Dear TMS Staff,

I know Drag and Drop is possibile on TAdvPolyList.
I would like to know if is it possible to drag & drop over an item  (TCustomItem, TImageItem, and so on..)
If already possible, or deriving my own Item.
Looking into TCustomItem in can't find where to find DragOver and DragDrop events.
Please could you give me a suggestion? thank you

Hi, 


Drag & Drop needs to be implemented manually, below is code that inserts or adds an item based on TCustomItem. The item also be a custom class that inherits from TCustomItem.
The code below is drag & drop code based on 2 TAdvPolyList instances, where the item to be dropped is obtained from the DropItem function. But the Source can come from another component as well.

procedure TForm1.AdvPolyList1DragDrop(Sender, Source: TObject; X, Y: Integer);
var
  it, itdrop: TCustomItem;
begin
  it := (Source as TAdvPolyList).DropItem;
  itdrop := AdvPolyList1.List.ItemAtXY(X, Y);
  if Assigned(itdrop) then
    AdvPolyList1.InsertItem(itdrop.Index, TCustomItemClass(it.ClassType)).Assign(it)
  else
    AdvPolyList1.AddItem(TCustomItemClass(it.ClassType)).Assign(it);
end;

procedure TForm1.AdvPolyList1DragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
begin
  Accept := Source is TAdvPolyList;
end;

Thank you. Very clear answer.

Key is AdvPolyList1.List.ItemAtXY(X, Y) method, which allows to guess which item is under the mouse pointer.

Dear Pieter,

I Imagine that DropItem could also be used on a DragOver event in order to decide if the item can be accepted or not. However, it seems that sometimes DropItem() is correctly set, sometimes no.
Having 2 AdvPolyLists, each one with 3 ImageItems, and starting to drag and ImageItem from the first to the second list the following exception is sometimes fired.
(Please note that I always start the drag from an ImageItem., not from the list background).



void __fastcall TForm1::PolyListADragOver(TObject *Sender, TObject *Source,
 int X, int Y, TDragState State, bool &Accept)
{
bool accept=false;
TAdvPolyList * LFrom = dynamic_cast <TAdvPolyList * > (Source);
if (LFrom)
if (LFrom->DropItem()==NULL) throw(Exception("AAArgh!"));
}

PS (please do not consider "bool accept=false", it has no meaning in the example)

DropItem is reinitialized each time a DragOver event occurs on the TCustomItemsContainer. So while you are dragging an item outside of the list it could be possible that the last X/Y coördinates do not detect an item and therefore setting FDropItem to nil. To make sure you are always dragging an item, it would be better to use the OnMouseDown event and set a FDropItem variable manually via the ItematXY function