I have 2 TreeNodeShapes with a connection between them. I try and add some additional points to the connection. The added points appear but the end points are no longer "linked" to the Shapes. I've tried reassigning the ToShape,FromShape nothing. How can you progamatically reconnect the connection to the shapes ??
I'm missing something.
Thanks,
Sample Code.
var
nd : TTreeNodeShape;
nd2 : TTreeNodeShape;
cn : TTreeConnection;
cp : TConnectionPoint;
p : TPen;
begin
t1.Designing := true;
nd := t1.Items.AddChild(nil,'Hello?');
nd.Style := tssRectangle;
nd.Top := 120;
nd.left := 120;
nd2 := t1.Items.AddChild(nil,'World');
nd2.Style := tssRectangle;
nd2.Top := 120;
nd2.left := 320;
cn := nd.addconnection(nd2);
cn.Points.add(cpsfixed,120,cpsfixed,120);
cn.Points.add(cpsfixed,220,cpsfixed,220);
cn.Points.add(cpsfixed,320,cpsfixed,120);
cn.Border.SmallDots := false;
cn.Border.Style := pssolid;
cn.border.width := 1;
cn.SimpleText := 'Stuff';
cn.FromShape := nd;
cn.ToShape := nd2;
TTree ConnectionPoints
Hi,
With cpsFixed you tell teeTree to put a point on a fixed x,y position.
You should use the following code:
with cpsAutoFrom and cpsAutoTo you attach the connection to the From and To shape respectively. The provided x and y values are not really needed in this case, since they are set by the from and to shapes, however there is a slight difference, you can see this by using the following code instead (look ath the starting position of the connection):
There are several other ways to add/insert points (you are not always obliged to proved a connectionpointstyle). e.g. If you create the third point at another moment, you can also use the following code (in this case we use the insert instead of the add method):
The different ways to specify the connection points coordinates:
Regards,
Tom
With cpsFixed you tell teeTree to put a point on a fixed x,y position.
You should use the following code:
Code: Select all
cn.Points.Add(cpsAutoFrom, 120, cpsAutoFrom, 120);
cn.Points.Add(cpsPrevious, 100, cpsPrevious, 100);
cn.Points.Add(cpsAutoTo, 320, cpsAutoTo, 120);
Code: Select all
cn.Points.Add(cpsAutoFrom, 0, cpsAutoFrom, 0);
Code: Select all
procedure TForm1.Button1Click(Sender: TObject);
var
nd : TTreeNodeShape;
nd2 : TTreeNodeShape;
cn : TTreeConnection;
begin
t1.Designing := true;
nd := t1.Items.AddChild(nil,'Hello?');
nd.Style := tssRectangle;
nd.Top := 120;
nd.left := 120;
nd2 := t1.Items.AddChild(nil,'World');
nd2.Style := tssRectangle;
nd2.Top := 120;
nd2.left := 320;
cn := nd.addconnection(nd2);
cn.Style := csLine;
cn.Border.SmallDots := false;
cn.Border.Style := pssolid;
cn.border.width := 1;
cn.SimpleText := 'Stuff';
end;
procedure TForm1.Button2Click(Sender: TObject);
var
cn : TTreeConnection;
begin
//one of the possible ways to select a connection
cn := t1.Connections[0];
//insert a point to the already existing code
cn.Points.Insert(1, 220,220);
cn.Repaint;
end;
The different ways to specify the connection points coordinates:
Code: Select all
cpsAutoFrom Automatic position on the "From" node
cpsAutoTo Automatic position on the "To" node
cpsFromPercent + / - percent on "From" size
cpsToPercent + / - percent on "To" size
cpsFromRel + / - pixels relative from "From" node origin
cpsToRel + / - pixels relative from "To" node origin
cpsPrevious + / - pixels relative to Previous Point in array
cpsNext + / - pixels relative to Next Point array
cpsFixed Fixed XY pixel position
Tom