Delete a Node in SimpleGraph in the event OnObjectInsert

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

Delete a Node in SimpleGraph in the event OnObjectInsert

Postby onlytk » November 10th, 2005, 2:28 am

Hi everybody, i'm again :oops:

I'm doing a program that ask a question when the node is inserted, it ask for the input of the name of the node, every node have to a name, and if the user dont put a name the Node have to delete, i do this:

Code: Select all
procedure TfrmMainWnd.sgAreaObjectInsert(Graph: TSimpleGraph;
  GraphObject: TGraphObject);
var
    inputOK : Boolean;
    strInput: String;
begin
    inputOK := False;
    if GraphObject is TTriangularNode then
    begin
        repeat
            if InputQuery(Application.Title, 'Name of the Node:', strInput) then
            begin
                if strInput = '' then
                    ShowMessage('You have to put a name')
                else
                    TTriangularNode(GraphObject).Text := strInput;
                    inputOK := True;
                end;
            end
            else
            begin
               inputOK := True;
                sgArea.BeginUpdate;
                try
                    TTriangularNode(GraphObject).Free;
                finally
                      sgArea.EndUpdate;
                end;
            end;
        until inputOK;
    end;
end;


Im using only Triangles for the Nodes, but the problem is that when the user push in CANCEL, the the sentence TTriangularNode(GraphObject).Free; stop the application.

someone can help me??? or what i'm doing wrong?
onlytk
Active Member
Active Member
 
Posts: 9
Joined: October 30th, 2005, 1:46 am

Postby Kambiz » November 10th, 2005, 1:37 pm

Use the following code:

Code: Select all
procedure TfrmMainWnd.sgAreaObjectInsert(Graph: TSimpleGraph;
  GraphObject: TGraphObject);
var
  inputOK : Boolean;
  strInput: String;
begin
  if GraphObject is TTriangularNode then
  begin
    inputOK := False;
    strInput := '';
    repeat
      if InputQuery(Application.Title, 'Name of the Node:', strInput) then
      begin
        if strInput = '' then
          ShowMessage('You have to put a name')
        else
        begin
          GraphObject.Text := strInput;
          inputOK := True;
        end;
      end
      else
      begin
        GraphObject.Free;
        sgArea.CommandMode := cmEdit;
        Abort;
      end;
    until inputOK;
  end;
end;
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

thanx, its OK

Postby onlytk » November 10th, 2005, 4:49 pm

Hi Kambiz, thanx a lot its OK, thanx :D
onlytk
Active Member
Active Member
 
Posts: 9
Joined: October 30th, 2005, 1:46 am


Return to DELPHI AREA Products

Who is online

Users browsing this forum: No registered users and 1 guest