Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Make the user required to enter text in a InputQuery.

Posted on 2009-07-16
9
Medium Priority
?
199 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
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
Industry Leaders: 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 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

772 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