Input form dissapears when closing a message.

Peter Kiers
Peter Kiers used Ask the Experts™
on
Dear Experts,

I have an application with a Treeview on it and 2 buttons.
One button is for making a File-node in the treeview and
the other is for making a Folder-node in the treeview.

f.e: When the user clicks on the Folder-node button to create
a folder-node in the treeview, a little input-form (NewFolderFrm)
appears with an edit-field on it and an OK and Cancel button.
The user MUST put some text in de edit-field, if he/she doesn't
a message appears: You must enter a folder name.


BUT when the user presses OK of the message. The NewFolderFrm
closes too!!! How can I prevent the NewFolderFrm from closing?

Who can help me with this?

Greetings, Peter Kiers



procedure TNewFolderFrm.OKBtn2Click(Sender: TObject);
begin
  if Edit2.Text <> '' then
    ModalResult := mrOk
     else
    MessageBox(0, 'You must enter a folder name.', 'Error', MB_OK + MB_ICONEXCLAMATION);
end;
 
procedure TNewItemFrm.OKBtn1Click(Sender: TObject);
begin
  if Edit1.Text <> '' then
    ModalResult := mrOk
     else
    MessageBox(0, 'You must enter an item name.', 'Error', MB_OK + MB_ICONEXCLAMATION);
end;
 
procedure TForm1.FileBtnClick(Sender: TObject);
begin
  if (TreeView1.Selected <> nil) and
     (TreeView1.Selected.ImageIndex = 15) and
     (NewItemFrm.ShowModal = mrOk ) then
     AddItem(NewItemFrm.Edit1.Text ,17,TreeView1.Selected);
end;
 
procedure TForm1.FolderBtnClick(Sender: TObject);
 begin
  if (TreeView1.Selected <> nil) and
     (TreeView1.Selected.ImageIndex = 15) and
     (NewFolderFrm.ShowModal = mrOk ) then
          AddItem(NewFolderFrm.Edit2.Text ,15,TreeView1.Selected);
end;
 
procedure TForm1.AddItem(aText: string; aIndex: Integer; aParent: TTreeNode);
var n: TTreeNode;
  data: TItem;
  parentId: integer;
begin
  parentId := 0;
  if (aParent <> nil) and (TItem(aParent.Data) <> nil) then
    parentId := TItem(aParent.Data).ID;
  data := TItem.Create(AdoQuery1, -1, parentId, 0);
  data.NodeText := aText;
  data.ImageIndex := aIndex;
  n := TTreeNode.Create(TreeView1.Items);
  n.Text := data.NodeText;
  n.ImageIndex := data.ImageIndex;
  n.SelectedIndex := data.ImageIndex;
  TreeView1.Items.AddNode(n, aParent, aText, data, naAddChild);
end;

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Does your button have it's ModalResult property set?
Peter KiersOperator

Author

Commented:
 
Properties of the OK-button to make a File-node:

  object OKBtn1: TButton
    Left = 62
    Top = 59
    Width = 75
    Height = 25
    Caption = 'OK'
    Default = True
    ModalResult = 1
    TabOrder = 1
    OnClick = OKBtn1Click

Properties of the OK-button to make a Folder-node:

object OKBtn2: TButton
    Left = 62
    Top = 59
    Width = 75
    Height = 25
    Caption = 'OK'
    Default = True
    ModalResult = 1
    TabOrder = 1
    OnClick = OKBtn2Click
Commented:
Change your ModalResult to mrNone before displaying MessageBox.
Commented:
"Change your ModalResult to mrNone before displaying MessageBox."
That's where I was heading...
Peter KiersOperator

Author

Commented:
Thanks for your help.

Greetings, Peter Kiers

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial