FindObjectAt

Please discuss general Delphi programming topics here.

FindObjectAt

Postby Vein » January 29th, 2007, 3:46 pm

Hi!

(I am new to Delphi, but still trying :D)

I am trying to draw a 'tree-like' directed graph with TSimpleGraph. The graph consists of nodes and links between the nodes in a 'collect-like' fashion.

What i mean is that i draw a link from a 'parent' node to another, horizontal link below it. Then i loop through the nodes that are supposed to be below that link and for each node that should, will get a link from the horizontal link to itself.

And i though of using the 'SimpleGraph.FindObjectAt(X,Y, [LookAfter:TGraphObject])' function to find the horizontal link again since i re-use the variable for it to draw another horizontal link elsewhere before i draw the nodes for the first horizontal link.

The problem is that the function gives me only 'nil' as an answer, eventhough i know that there should be a Link in the point i use the function on. (The horizontal links are always at the same height from the nodes)

So what am i doing wrong? Please give me some help, i am all new to Delphi too.
/VEIN
(Trying to become a Delphi-Developer)
Vein
Member
Member
 
Posts: 3
Joined: January 29th, 2007, 3:27 pm

Postby Kambiz » January 29th, 2007, 4:04 pm

X and Y are in Graph coordinates. Did you pass the correct coordinates?

  • To convert Screen to Graph coordinates use ScreenToGraph method.
  • To convert SG's Client to Graph coordinates use ClientToGraph method.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2421
Joined: March 7th, 2003, 7:10 pm

Postby Vein » January 29th, 2007, 4:52 pm

Kambiz wrote:X and Y are in Graph coordinates. Did you pass the correct coordinates?

  • To convert Screen to Graph coordinates use ScreenToGraph method.
  • To convert SG's Client to Graph coordinates use ClientToGraph method.


Hmm...the coordinates i gave the function is in the same format as the ones that i gave to the 'insertLink(array of Tpoint)' function. That should make them Client coordinates, right? But still when i tested that, i got nil as answer... Going to do some more testing...

Thanks for the fast answering :D
/VEIN
(Trying to become a Delphi-Developer)
Vein
Member
Member
 
Posts: 3
Joined: January 29th, 2007, 3:27 pm

Postby Kambiz » January 29th, 2007, 4:58 pm

The InsertLink method - as like as other graph related methods - uses graph coordinates.

Can you please post here a sample code to regenerate the issue?
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2421
Joined: March 7th, 2003, 7:10 pm

Postby Vein » January 29th, 2007, 5:29 pm

Kambiz wrote:The InsertLink method - as like as other graph related methods - uses graph coordinates.

Can you please post here a sample code to regenerate the issue?


Ok, first i insert the Link by:

Code: Select all
LinkPoints[1].X := Round(GraphStruct.Node(i).X -((GraphStruct.Node(i).CountLinks-countNotIn)/2*nodeWidth+spaceBetween));

//Put link one nodeHeight below the node
LinkPoints[1].Y := Round(GraphStruct.Node(i).Y+nodeHeight);

LinkPoints[2].X := Round(GraphStruct.Node(i).X+nodeWidth + ((GraphStruct.Node(i).CountLinks- countNotIn)/2*nodeWidth+spaceBetween));
       
LinkPoints[2].Y := Round(GraphStruct.Node(i).Y+nodeHeight);

LinkBetween := Graph.InsertLink(LinkPoints);
LinkBetween.EndStyle := lsNone;



Where:
GraphStruct is an ordinary adj. list structure for graphs

I hope the rest is obvious. :)

Then i try to find the link again by:

Code: Select all
Node := NodeSearch(Target,GraphStruct);
LinkBetween := TGraphLink(Graph.FindObjectAt(Node.Left,Node.Top-nodeHeight));
if(LinkBetween = nil) then
   LinkBetween := TGraphLink(Graph.FindObjectAt(Node.Left+nodeWidth,Node.Top-nodeHeight));


And here the NodeSearch function is tested and working. And it the node is previously added '2*nodeHeight' below the parent node below which the 'LinkBetween' is added.
/VEIN
(Trying to become a Delphi-Developer)
Vein
Member
Member
 
Posts: 3
Joined: January 29th, 2007, 3:27 pm


Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 2 guests

cron