InsertLink with access violation

Please post bug reports, feature requests, or any question regarding the DELPHI AREA projects here.

InsertLink with access violation

Postby HPW » March 4th, 2006, 11:10 pm

I have most of demo now working with my plugin.
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?
Hans-Peter
HPW
Moderator
Moderator
 
Posts: 238
Joined: February 25th, 2006, 10:19 am
Location: Germany

Postby HPW » March 5th, 2006, 8:27 am

Further observations:

Code: Select all
showmessage('InsLink3');
          InsertedObject := InsertLink(ObjectAtCursor, [Pt]);


That line calls this:

Code: Select all
function TSimpleGraph.InsertLink(Source: TGraphObject; const Pts: array of TPoint;
  ALinkClass: TGraphLinkClass): TGraphLink;
var
  I: Integer;
begin
showmessage('InsertLink2_1');
  BeginUpdate;
  try
    SelectedObjects.Clear;
showmessage('InsertLink2_2');
    if not Assigned(ALinkClass) then
      ALinkClass := DefaultLinkClass;
showmessage('InsertLink2_3');
    Result := ALinkClass.Create(Self);
showmessage('InsertLink2_4');
    if Result.Hook(0, Source) then
    begin
showmessage('InsertLink2_5');
      for I := Low(Pts) to High(Pts) do
        begin
        showmessage('InsertLink2_6: '+IntToStr(I));
        Result.AddPoint(Pts[I]);
        END;
showmessage('InsertLink2_7');
      Result.State := osNone;
      Result.Selected := True;
    end
    else
    begin
showmessage('InsertLink2_8');
      Result.Free;
      Result := nil;
    end;
  finally
    EndUpdate;
  end;
end;


It run to:
showmessage('InsertLink2_6: '+IntToStr(I));

until counter I reach 626 then it crashes with Access violation.

(running delphi 5 standard on WIN XP german)
Hans-Peter
HPW
Moderator
Moderator
 
Posts: 238
Joined: February 25th, 2006, 10:19 am
Location: Germany

Postby Kambiz » March 5th, 2006, 11:33 am

I was already fixed this bug for the new release. :)

The bug is in Delphi 4 and 5 compilers that cannot find the proper overloaded function.

As a workaround for this bug in Delphi4 and Delphi5, change the code as follow:

Code: Select all
    cmInsertLink:
      if (Button = mbLeft) and not (ssDouble in Shift) then
      begin
        ObjectAtCursor := FindObjectAt(Pt.X, Pt.Y);
        if Assigned(ObjectAtCursor) then
          begin
          InsertedObject := InsertLink(ObjectAtCursor, [Pt], DefaultLinkClass);
          END;
        if not Assigned(InsertedObject) then
        begin
          Pt := SnapPoint(Pt, gsDefault);
          if GraphConstraints.WithinBounds([Pt]) then
            InsertedObject := InsertLink([Pt, Pt], DefaultLinkClass);
        end;
        ObjectAtCursor := InsertedObject;
      end;
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Postby HPW » March 5th, 2006, 12:42 pm

Thanks very much for the quick response!
Works now as expected.

Any timeline for the new release?
Hans-Peter
HPW
Moderator
Moderator
 
Posts: 238
Joined: February 25th, 2006, 10:19 am
Location: Germany


Return to DELPHI AREA Projects

Who is online

Users browsing this forum: No registered users and 1 guest

cron