procedure TForm1.VSTDragOver(Sender: TBaseVirtualTree;
Source: TObject; Shift: TShiftState; State: TDragState; Pt: TPoint;
Mode: TDropMode;
var Effect: Integer;
var Accept: Boolean);
begin
if Source=VST
then Accept := True;
end;
procedure TForm1.VSTDragDrop(Sender: TBaseVirtualTree;
Source: TObject; DataObject: IDataObject; Formats: TFormatArray;
Shift: TShiftState; Pt: TPoint;
var Effect: Integer; Mode: TDropMode);
var
S:
string;
Attachmode: TVTNodeAttachMode;
Nodes: TNodeArray;
I: Integer;
//--------------- local function --------------------------------------------
procedure DetermineEffect;
// Determine the drop effect to use if the source is a Virtual Treeview.
begin
// In the case the source is a Virtual Treeview we know 'move' is the default if dragging within
// the same tree and copy if dragging to another tree. Set Effect accordingly.
if Shift = []
then
begin
// No modifier key, so use standard action.
if Source = Sender
then
Effect := DROPEFFECT_MOVE
else
Effect := DROPEFFECT_COPY;
end
else
begin
// A modifier key is pressed, hence use this to determine action.
if (Shift = [ssAlt])
or (Shift = [ssCtrl, ssAlt])
then
Effect := DROPEFFECT_LINK
else
if Shift = [ssCtrl]
then
Effect := DROPEFFECT_COPY
else
Effect := DROPEFFECT_MOVE;
end;
end;
//--------------- end local function ----------------------------------------
begin
Nodes :=
nil;
// Translate the drop position into an node attach mode.
case Mode
of
dmAbove:
AttachMode := amInsertBefore;
// dmOnNode:
// AttachMode := amAddChildLast; //<------ hier deaktiviert
dmBelow:
AttachMode := amInsertAfter;
else
AttachMode := amNowhere;
end;
if DataObject =
nil then
begin
// VCL drag'n drop. Handling this requires detailed knowledge about the sender and its data. This is one reason
// why it was a bad decision by Borland to implement something own instead using the system's way.
// In this demo we have two known sources of VCL dd data: Tree2 and LogListBox.
end
else
begin
// OLE drag'n drop. Perform full processing.
if Source
is TBaseVirtualTree
then
begin
DetermineEffect;
end
else
if Boolean(Effect
and DROPEFFECT_COPY)
then
Effect := DROPEFFECT_COPY
else
Effect := DROPEFFECT_MOVE;
InsertData(Sender
as TVirtualStringTree, DataObject, Formats, Effect, AttachMode);
end;
end;