Page 1 of 1

About TSimpleGraph Lines and Objects

PostPosted: August 13th, 2008, 8:38 am
by BlackJack
I have some questions about Lines and Objects,please help me.

with Lines:

1. I want connect Object A and Object B with a broken line,what should i do it?

2. I want add to some properties.
e.g:
TempStr : String;
TempInt : Integer;

with Objects:

1. Add new Objects
2. Modefy Objects
3. Add some new properties like String,Integer ... so on.

How to do it?Please show me the codes If possible,Thanks again.

PostPosted: August 13th, 2008, 1:28 pm
by Kambiz
The first question:

Use InsertLink to link two objects, then use AddPoint method of created link object to add the break point.


The second question:

Define new object by subclassing from existing objects, then add your new properties to the published section of the new class. For example the following class defines a new object that defines a Reactangular node, which has a datetime property.

Code: Select all
TMyRectangularNode = class(TRectangularNode)
private
  fMyProperty: TDateTime;
protected
  property MyProperty: TDateTime read fMyProperty write fMyProperty;
end;


Don't forget to register your class.

Code: Select all
TSimpleGraph.Register(TMyRectangularNode);


There is another way to save/load custom data with each object. Take look at OnObjectWrite and OnObjectRead events of SimpleGraph.

PostPosted: August 15th, 2008, 7:33 am
by BlackJack
Thank you,Kambiz.

The first question i solved by your help,thanks again. =D>

But the second question i don't understand how to do it yet. :oops:

your mean create a descendants class of TRectangularNode,add some properties what i want,there is no problem.Next register my class.i want to know where i put the codes,in source or my file?

I use InsertNode to insert a object like this:
Code: Select all
 SimpleGraph.InsertNode(rect,Tmyobject);


Tmyobject is a descendants class of TRectangularNode.

but 'InsertNode' returns a object of TGraphNode,not Tmyobject,what should i do?

thanks again!

PostPosted: August 15th, 2008, 11:19 am
by Kambiz
InsertNode always returns the new node as TGraphNode, which is base class for all node classes.

But you know that you have created a TMyObject, so you can easily typecast the returned value to TMyObject. For example:

Code: Select all
var MyNode: TMyObject;
MyNode := SimpleGraph.InsertNode(rect, TMyObject) as TMyObject;

PostPosted: August 15th, 2008, 4:56 pm
by BlackJack
Thanks very mach Kambiz, i know how to do it by your help,thanks again. =D>