Solved

Make the user required to enter text in a InputQuery.

Posted on 2009-07-16
9
189 Views
Last Modified: 2012-05-07
Dear Experts,

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

My question: When the user f.e press the Folder-node button
to make a folder-node in the treeview, an Input-query appears
the edit-field may not be empty, the user must put some text
in it, if he doesn't put text in it and press the OK-button a message
appears. I have put a picture in the attach.

Who can help me to solve my problem?

Greetings, Peter Kiers
procedure TForm1.FileBtnClick(Sender: TObject);

var aText: string;

begin

  if (TreeView1.Selected <> nil) and (TreeView1.Selected.ImageIndex = 15) then

  begin

     if InputQuery('File', 'Enter a file name', aText) then

      AddItem(aText, 17, TreeView1.Selected);

  end else

    ShowMessage('Select a folder in the treeview first.');

end;

(*---------------------------------------------------*)

procedure TForm1.FolderBtnClick(Sender: TObject);

var aText: string;

  aParent: TTreeNode;

begin

  aParent := nil;

  if TreeView1.Selected <> nil then

  begin

    if TreeView1.Selected.ImageIndex = 15 then

      aParent := TreeView1.Selected

    else

    begin

      ShowMessage('Select a folder first');

      Exit;

    end;

  end;

  if InputQuery('Folder', 'Enter a folder name', aText) then

    AddItem(aText, 15, aParent);

end;

Open in new window

Example2.bmp
0
Comment
Question by:peterkiers
  • 6
  • 3
9 Comments
 
LVL 6

Expert Comment

by:bokist
Comment Utility
Try this way:

procedure TForm1.FileBtnClick(Sender: TObject);
var aText: string;
begin
  aText := '';
  if (TreeView1.Selected <> nil) and (TreeView1.Selected.ImageIndex = 15) then
  begin
     if InputQuery('File', 'Enter a file name', aText) then
        begin
        if lenght(trim(aText)) > 0 then  AddItem(aText, 17, TreeView1.Selected)
        else Showmessage('You must enter a file name');
     end;  
  end else
    ShowMessage('Select a folder in the treeview first.');
end;
(*---------------------------------------------------*)
procedure TForm1.FolderBtnClick(Sender: TObject);
var aText: string;
  aParent: TTreeNode;
begin
  aParent := nil;
  if TreeView1.Selected <> nil then
  begin
    if TreeView1.Selected.ImageIndex = 15 then
      aParent := TreeView1.Selected
    else
    begin
      ShowMessage('Select a folder first');
      Exit;
    end;
  end;
  if InputQuery('Folder', 'Enter a folder name', aText) then
      begin
      if lenght(trim(aText)) > 0 then  AddItem(aText, 15, aParent)
      else Showmessage('You must enter a folder name');
  end;      
end;
0
 
LVL 1

Author Comment

by:peterkiers
Comment Utility
Oke, one little thing.

When the user puts nothing in the editbox, the message will appear
the user than click the ok-button of the message and the message will go away.
But also the InputQuery, and that has to stay!

Peter
0
 
LVL 1

Author Comment

by:peterkiers
Comment Utility
And I want to use a MessageBox, because i want a iconinformation it.
just like the picture.

Greetings, Peter Kiers
0
 
LVL 6

Accepted Solution

by:
bokist earned 500 total points
Comment Utility
I'm not sure it can be done as you like.(Because both dialogs are TopMost Style).
Anyway, here is one kind of solutions :

 procedure TForm1.FileBtnClick(Sender: TObject);
var aText: string;
begin
  aText := '';
  if (TreeView1.Selected <> nil) and (TreeView1.Selected.ImageIndex = 15) then
      begin
      InputQuery('File', 'Enter a file name', aText);
      if lenght(trim(aText)) = 0 then
         begin
         repeat
              if not (InputQuery('       WRONG FILE NAME   !!! ', 'You must enter file name ', aText)) then Break;
         until length(trim(aText)) > 0;
      end;
       if lenght(trim(aText)) > 0 then  AddItem(aText, 17, TreeView1.Selected);
     end;  
  end else
    ShowMessage('Select a folder in the treeview first.');
end;

regards,
 steve
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 1

Author Comment

by:peterkiers
Comment Utility
Thank you for your responce. Ill be back in an hour to try your example.
0
 
LVL 1

Author Comment

by:peterkiers
Comment Utility
b.t.w: it's possible because the picture I posted is from another application
that works like that.

PK
0
 
LVL 1

Author Comment

by:peterkiers
Comment Utility
I have tried your example and its not want i wanted.

In steps:
1. The user clicks on the folder button, to make a folder node.
2. The input-query appears where the user can enter a name for the node and the press OK
3. The user must put some text in the input-query, because when he doesn't en press OK
    a message appears
4. The user can click away the message by pressing ok, and the input-query is still there
    for enter the text of the node.
0
 
LVL 1

Author Comment

by:peterkiers
Comment Utility
I adjust it a little bit:

procedure TForm1.FileBtnClick(Sender: TObject);
var aText: string;
begin
  aText := '';
  if (TreeView1.Selected <> nil) and (TreeView1.Selected.ImageIndex = 15) then
  begin
     if InputQuery('New Item', 'New Item Name:', aText) then
        begin
        if length(trim(aText)) > 0 then  AddItem(aText, 17, TreeView1.Selected)
        else MessageBox(0, 'You must enter an item name.', 'Error', MB_OK + MB_ICONEXCLAMATION);
     end;  
  end else
    ShowMessage('Select a folder in the treeview first.');
end;

procedure TForm1.FolderBtnClick(Sender: TObject);
var aText: string;
  aParent: TTreeNode;
begin
  aParent := nil;
  if TreeView1.Selected <> nil then
  begin
    if TreeView1.Selected.ImageIndex = 15 then
      aParent := TreeView1.Selected
    else
    begin
      ShowMessage('Select a folder first');
      Exit;
    end;
  end;
  if InputQuery('New Folder', 'New Folder Name:', aText) then
      begin
      if length(trim(aText)) > 0 then  AddItem(aText, 15, aParent)
      else MessageBox(0, 'You must enter a folder name.', 'Error', MB_OK + MB_ICONEXCLAMATION);
  end;
end;

The only problem with the procedures above is when the messagebox appears the Input-querie dissapears
Peter
0
 
LVL 6

Expert Comment

by:bokist
Comment Utility

I have also tested messagebox, messagedlg and showmessage but no success.
In either case InputQuery has disappeared.
I have little improved InputQuery, try this solution:

  private
    procedure ApplicationOnMessage(var Msg: TMsg; var Handled: Boolean);


in FormCreate event  put
    Application.OnMessage := Form1.ApplicationOnMessage;

procedure TForm1.ApplicationOnMessage(var Msg: TMsg; var Handled: Boolean);
var
  QEdit : TEdit;
  QLab : TLabel;
begin
  with Screen.ActiveForm do
     begin
     if (Caption =  'File')  or  
        (Caption =  'Folder') then
        begin
        QLab := Components[0] as TLabel;
        QEdt := Components[1] as TEdit;
        QEdt.Font.Color := clBlack;
        QLab.Font.Color := clBlack;
        QLab.Font.Style := [];
     end;
     if pos('ERROR', Caption) > 0  then
        begin
        QLab := Components[0] as TLabel;
        QEdt := Components[1] as TEdit;
        QEdt.Font.Color := clRed;
        QLab.Font.Color := clRed;
        QLab.Font.Style := [fsBold];
     end;
  end;
end;

procedure TForm1.FileBtnClick(Sender: TObject);
var aText: string;
begin
  aText := '';
  if (TreeView1.Selected <> nil) and (TreeView1.Selected.ImageIndex = 15) then
      begin
      InputQuery('File', 'Enter a file name', aText);
      if length(trim(aText)) = 0 then
         begin
         repeat
              if not (InputQuery('ERROR  - WRONG FILE NAME   !!! ', 'You must enter file name ', aText)) then Break;
         until length(trim(aText)) > 0;
      end;
      if length(trim(aText)) > 0 then  AddItem(aText, 17, TreeView1.Selected);
     end;  
  end else
    ShowMessage('Select a folder in the treeview first.');
end;

Thanks for the points.
regards,
 steve

0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now