Board index » delphi » TTreeView and OnDragOver event problem

TTreeView and OnDragOver event problem

In order to implement accept and reject images when dragging
a TreeNode in a TreeView, I've build a little test function as
follows:

procedure TExplorer.TreeViewDragOver(Sender, Source: TObject; X,
  Y: Integer; State: TDragState; var Accept: Boolean);
var
 sLevel, dLevel:integer;
begin

 if (Source is TTreeView) then
   sLevel:=TTreeView(Source).Selected.ImageIndex

 if (Source is TTreeView) then
   dLevel:=TTreeView(Sender).DropTarget.ImageIndex

    Label.Caption:=Format('source %d to sender %d',[sLevel, dLevel]));
end;

The problem with the code above is that it crashes when
accessing the DropTarget.ImageIndex property. I noticed that
the DropTarget property has value NIL. Needless to say it crashes
my app big time.

OK, I admit I don't get it. Should the DropTarget property not
contain a pointer to the TreeNode that is the target of my D&D
action ?

-j-

PS TreeView.DragMode:=dmManual in case you'd ask.

 

Re:TTreeView and OnDragOver event problem


Hi JB!
your only simple and innocent mistake is that the 'DropTarget' gets value in
the 'OnDragDrop' event and not in 'OnDragOver' event. move the relevant
declerations to the 'OnDragDrop'  event :

procedure TForm1.TreeView1DragDrop(Sender, Source: TObject; X, Y: Integer);
var

Quote
> sLevel, dLevel:integer;
>begin

> if (Source is TTreeView) then
>   sLevel:=TTreeView(Source).Selected.ImageIndex

> if (Source is TTreeView) then
>   dLevel:=TTreeView(Sender).DropTarget.ImageIndex

>Label.Caption:=Format('source %d to sender %d',[sLevel, dLevel]));
>end;

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

eyal wilde

Quote
JB wrote in message <354EAE77.3E92E...@ibm.net>...
>In order to implement accept and reject images when dragging
>a TreeNode in a TreeView, I've build a little test function as
>follows:

>procedure TExplorer.TreeViewDragOver(Sender, Source: TObject; X,
>  Y: Integer; State: TDragState; var Accept: Boolean);
>var
> sLevel, dLevel:integer;
>begin

> if (Source is TTreeView) then
>   sLevel:=TTreeView(Source).Selected.ImageIndex

> if (Source is TTreeView) then
>   dLevel:=TTreeView(Sender).DropTarget.ImageIndex

>    Label.Caption:=Format('source %d to sender %d',[sLevel, dLevel]));
>end;

>The problem with the code above is that it crashes when
>accessing the DropTarget.ImageIndex property. I noticed that
>the DropTarget property has value NIL. Needless to say it crashes
>my app big time.

>OK, I admit I don't get it. Should the DropTarget property not
>contain a pointer to the TreeNode that is the target of my D&D
>action ?

>-j-

>PS TreeView.DragMode:=dmManual in case you'd ask.

Other Threads