Solved

Make the user required to enter text in a InputQuery.

Posted on 2009-07-16
9
192 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

810 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