Page 1 of 1

Delete a Node in SimpleGraph in the event OnObjectInsert

PostPosted: November 10th, 2005, 2:28 am
by onlytk
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?

PostPosted: November 10th, 2005, 1:37 pm
by Kambiz
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;

thanx, its OK

PostPosted: November 10th, 2005, 4:49 pm
by onlytk
Hi Kambiz, thanx a lot its OK, thanx :D