rdaniell
asked on
DoEndDrag
I am attempting to enhance the drag and drop behaviour
of a data-aware version of a TreeView component using
Delphi 3.0. I need to update a dataset field with the new
absoluteindex of a node when it is dragged from one location in the tree to another. I am overriding the 'DoEndDrag' procedure but any attempts to access the
'Target' parameter in order to determine the index of the node receiving the dragged node raises an EAccessViolation exception.
E.g.
procedure MyTree.DoEndDrag(Target: TObject; X, Y: Integer);
begin
ShowMessage((Target as TObject).ClassName);
...
inherited;
end;
Any assistance would be greatly appreciated.
Bob Daniells
of a data-aware version of a TreeView component using
Delphi 3.0. I need to update a dataset field with the new
absoluteindex of a node when it is dragged from one location in the tree to another. I am overriding the 'DoEndDrag' procedure but any attempts to access the
'Target' parameter in order to determine the index of the node receiving the dragged node raises an EAccessViolation exception.
E.g.
procedure MyTree.DoEndDrag(Target: TObject; X, Y: Integer);
begin
ShowMessage((Target as TObject).ClassName);
...
inherited;
end;
Any assistance would be greatly appreciated.
Bob Daniells
ASKER
Hi JimBob,
Many thanks for your prompt assistance! By using your
example code as a guide I was able to determine that the
problem lay elsewhere. I was using a descendant of the Treeview component rather that the original, and by reviewing its source I found some bad code that was always setting
Target to nil. Many thanks again.
Bob Daniells
Many thanks for your prompt assistance! By using your
example code as a guide I was able to determine that the
problem lay elsewhere. I was using a descendant of the Treeview component rather that the original, and by reviewing its source I found some bad code that was always setting
Target to nil. Many thanks again.
Bob Daniells
ASKER
Hi JimBob,
This is my first crack at using the experts-exchange, and I
omitted to offer you a grade. Considering that you took the
trouble to offer some code that worked and steered me in the
right direction, I reckon your response deserves an 'A'!
Regards,
Bob Daniells
This is my first crack at using the experts-exchange, and I
omitted to offer you a grade. Considering that you took the
trouble to offer some code that worked and steered me in the
right direction, I reckon your response deserves an 'A'!
Regards,
Bob Daniells
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
There are 2 things I thought of:
1) You are not checking that Target <> nil.
2) You are assuming that Target is a TTreeNode, but it is a TTreeView. This is unlikely, and in your example this would actually make no difference.
Just for you interest, the following code checks Target <> nil, and the node under the cursor <> nil. This code works fine.
procedure TMyTreeView.DoEndDrag(Targ
var
Node: TTreeNode;
begin
inherited;
if (Target <> nil) then begin
Node := TTreeView(Target).GetNodeA
if (Node <> nil) then ShowMessage('You dragged ' + Selected.Text + ' onto ' + Node.Text);
end;
end;
JB