Hi Kambiz; I had modified Simplegraph.pas like follows
- Code: Select all
function TSimpleGraph.InsertNode(pBounds: PRect; ANodeClass: TGraphNodeClass): TGraphNode;
begin
BeginUpdate;
try
SelectedObjects.Clear;
if ANodeClass = nil then
ANodeClass := DEFAULTNODESETTINGS.DesiredClass;//DefaultNodeClass;
Result := ANodeClass.Create(Self);
if pBounds <> nil then
Result.BoundsRect := pBounds^;
Result.State := osNone;
Result.Selected := True;
Result.Resizable:=DEFAULTNODESETTINGS.Resizable;
Result.Linkable:= DEFAULTNODESETTINGS.Linkable;
Result.Brush:= DEFAULTNODESETTINGS.Brush;
Result.Text:= DEFAULTNODESETTINGS.text;
Result.Pen:= DEFAULTNODESETTINGS.Pen;
Result.Hint:=DEFAULTNODESETTINGS.Hint;
Result.Visible:=DEFAULTNODESETTINGS.Visible;
Result.Font:= DEFAULTNODESETTINGS.Font;
finally
EndUpdate;
end;
end;
...using DEFAULTNODESETTINGS how I explained before. The matter is that DEFAULTNODESETTINGS is not necesary to assign this properties:
- Code: Select all
Result.Linkable:= DEFAULTNODESETTINGS.Linkable;
Result.Brush:= DEFAULTNODESETTINGS.Brush;
Result.Text:= DEFAULTNODESETTINGS.text;
Result.Pen:= DEFAULTNODESETTINGS.Pen;
Result.Hint:=DEFAULTNODESETTINGS.Hint;
Result.Visible:=DEFAULTNODESETTINGS.Visible;
Result.Font:= DEFAULTNODESETTINGS.Font;
... except because if I change it from the main, BeginUpdate and EndUpdate will be run 7 times. You wrote a piece of code to make changes to the lastnodeinserted (LastNodeInserted), but I'm not convinced.
I think the best way to make this is using the OnInsertNodeEvent ¿What do you think?
...well, I think the problem it's that the event runs inside TSimpleGraph.ObjectListChanged, so the BeginUpdate and EndUpdate will be run 7 times again...
I suggest that the DoObjectInsert(GraphObject); should be in function TSimpleGraph.InsertNode like follows:
- Code: Select all
function TSimpleGraph.InsertNode(pBounds: PRect; ANodeClass: TGraphNodeClass): TGraphNode;
begin
BeginUpdate;
try
SelectedObjects.Clear;
if ANodeClass = nil then
ANodeClass := DEFAULTNODESETTINGS.DesiredClass;//DefaultNodeClass;
Result := ANodeClass.Create(Self);
if pBounds <> nil then
Result.BoundsRect := pBounds^;
Result.State := osNone;
Result.Selected := True;
Result.Resizable:=DEFAULTNODESETTINGS.Resizable;
DoObjectInsert(GraphObject)
finally
EndUpdate;
end;
end;
And too:
- Code: Select all
function TSimpleGraph.LinkNodes(FromNode, ToNode: TGraphNode;
ALinkClass: TGraphLinkClass): TGraphLink;
begin
Result := nil;
if IsValidLink(nil, FromNode, ToNode) then
begin
BeginUpdate;
try
SelectedObjects.Clear;
if ALinkClass = nil then
ALinkClass := DEFAULTLINKSETTINGS.DesiredClass;
Result := ALinkClass.Create(Self);
Result.FromNode := FromNode;
Result.ToNode := ToNode;
Result.State := osNone;
Result.Selected := True;
DoObjectInsert(GraphObject)
finally
EndUpdate;
end;
end;
end;
So BeginUpdate and EndUpdate will be run just once...
Well, I don't have time now to test this what I'm telling you but
What dou you think??
PD:When I have my simplegraph.pas modified at my way i will send you to you take a look (I hope you like any of my ideas)