But now I try to use 'InsertLink' which give me an access violation:
- Code: Select all
procedure TSimpleGraph.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
Pt: TPoint;
ObjectAtCursor: TGraphObject;
begin
if not Focused then SetFocus;
Pt := ClientToGraph(X, Y);
ObjectAtCursor := nil;
InsertedObject := nil;
case CommandMode of
cmInsertNode:
if (Button = mbLeft) and not (ssDouble in Shift) then
begin
Pt := SnapPoint(Pt, gsDefault);
if GraphConstraints.WithinBounds([Pt]) then
begin
InsertedObject := InsertNode(MakeSquare(Pt, 0));
if Assigned(InsertedObject) then
begin
Pt := InsertedObject.BoundsRect.BottomRight;
Mouse.CursorPos := ClientToScreen(GraphToClient(Pt.X, Pt.Y));
ObjectAtCursor := InsertedObject;
end;
end;
end;
cmInsertLink:
if (Button = mbLeft) and not (ssDouble in Shift) then
begin
showmessage('InsLink1');
ObjectAtCursor := FindObjectAt(Pt.X, Pt.Y);
showmessage('InsLink2');
if Assigned(ObjectAtCursor) then
begin
showmessage('InsLink3');
InsertedObject := InsertLink(ObjectAtCursor, [Pt]);
END;
showmessage('InsLink4');
if not Assigned(InsertedObject) then
begin
Pt := SnapPoint(Pt, gsDefault);
if GraphConstraints.WithinBounds([Pt]) then
InsertedObject := InsertLink([Pt, Pt]);
end;
showmessage('InsLink5');
ObjectAtCursor := InsertedObject;
end;
else
if Assigned(DragSource) then
ObjectAtCursor := DragSource
else if CommandMode = cmEdit then
ObjectAtCursor := FindObjectAt(Pt.X, Pt.Y);
end;
if Assigned(InsertedObject) then
CommandMode := cmEdit;
if Assigned(ObjectAtCursor) then
ObjectAtCursor.MouseDown(Button, Shift, Pt)
else if (Button = mbLeft) and not (ssDouble in Shift) and
not (CommandMode in [cmInsertNode, cmInsertLink]) then
begin
InitDragObject(TGraphObject(Self), Pt, GHT_CLIENT);
Screen.Cursor := crCross;
end;
inherited MouseDown(Button, Shift, X, Y);
end;
I get to message InsLink3 so it seems to happen here:
InsertedObject := InsertLink(ObjectAtCursor, [Pt]);
Inserting all other nodetypes work with no problem.
Loading and editing linklines does also work.
What do I miss here?
Do I need to init something before?