Solved

Make the user required to enter text in a InputQuery.

Posted on 2009-07-16
9
194 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
9 Comments
 
LVL 6

Expert Comment

by:bokist
ID: 24867964
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
ID: 24868083
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
ID: 24868130
And I want to use a MessageBox, because i want a iconinformation it.
just like the picture.

Greetings, Peter Kiers
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Accepted Solution

by:
bokist earned 500 total points
ID: 24868384
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
 
LVL 1

Author Comment

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

Author Comment

by:peterkiers
ID: 24868490
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
ID: 24869366
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
ID: 24871082
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
ID: 24871531

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Find and Replace Stream with 0s 8 73
Delphi inherited method 6 80
Tvertscrollbox like a whatsapp layout 5 53
Firemonkey allowing RTL on android 6 56
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

726 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