Solved

Make the user required to enter text in a InputQuery.

Posted on 2009-07-16
9
190 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
A short film showing how OnPage and Connectwise integration works.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

929 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

11 Experts available now in Live!

Get 1:1 Help Now