Solved

DoEndDrag

Posted on 1997-10-31
4
147 Views
Last Modified: 2010-04-04
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
0
Comment
Question by:rdaniell
  • 2
  • 2
4 Comments
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1349245
Hi

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(Target: TObject; X, Y: Integer);
var
    Node: TTreeNode;
begin
    inherited;
    if (Target <> nil) then begin
        Node := TTreeView(Target).GetNodeAt(X, Y);
        if (Node <> nil) then ShowMessage('You dragged ' + Selected.Text + ' onto ' + Node.Text);
    end;
end;

JB
0
 

Author Comment

by:rdaniell
ID: 1349246
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

0
 

Author Comment

by:rdaniell
ID: 1349247
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
0
 
LVL 5

Accepted Solution

by:
JimBob091197 earned 100 total points
ID: 1349248
Hi

Glad to help you.  I assume you want an answer, and if so then this be it!!!

Regards,
JB
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now