Recent

Author Topic: Dialog question  (Read 4181 times)

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Dialog question
« on: January 01, 2021, 07:50:54 am »
I'm using tryInputQuery and it's doing the job. I modified it a bit and it looks like this:


I would like to be able to position and set the top, width and left. and width of the input string. Is that possible?

I read somewher there was a control that was more configurable but haven't been able to find anything on it.

Happy New Year

Code: Pascal  [Select][+][-]
  1.  procedure TForm1.TryInputQuery (AHDR : String; APrompt : String; out S : String);
  2.   var
  3.    QueryResult: Boolean;
  4.    Reply : string;
  5.   begin
  6.   InputQuery(AHDR, APrompt, False, Reply);
  7.   S := Reply;
  8.  end;                  
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

Handoko

  • Hero Member
  • *****
  • Posts: 5374
  • My goal: build my own game engine using Lazarus
Re: Dialog question
« Reply #1 on: January 01, 2021, 08:59:19 am »
Runtimely creating a from is not hard. Try this:

Code: Pascal  [Select][+][-]
  1. function RequestInput(Top, Left, Width: Integer; Caption, Prompt: string): string;
  2. var
  3.   aForm:  TForm;
  4.   aLabel: TLabel;
  5.   Edit:   TEdit;
  6.   Cancel: TBitBtn;
  7.   Ok:     TBitBtn;
  8. begin
  9.  
  10.   aForm                      := TForm.Create(nil);
  11.   aForm.Top                  := Top;
  12.   aForm.Left                 := Left;
  13.   aForm.Width                := Width;
  14.   aForm.Height               := 110;
  15.   aForm.Constraints.MinWidth := 200;
  16.   aForm.Caption              := Caption;
  17.   aLabel                     := TLabel.Create(aForm);
  18.   aLabel.Parent              := aForm;
  19.   aLabel.Top                 := 10;
  20.   aLabel.Left                := 20;
  21.   aLabel.Caption             := Prompt;
  22.   aLabel.AutoSize            := True;
  23.   Edit                       := TEdit.Create(aForm);
  24.   Edit.Parent                := aForm;
  25.   Edit.Top                   := 30;
  26.   Edit.Left                  := 20;
  27.   Edit.Width                 := Width - 40;
  28.   Cancel                     := TBitBtn.Create(aForm);
  29.   Cancel.Parent              := aForm;
  30.   Cancel.Top                 := 65;
  31.   Cancel.Left                := Width - 180;
  32.   Cancel.Kind                := bkCancel;
  33.   ok                         := TBitBtn.Create(aForm);
  34.   ok.Parent                  := aForm;
  35.   ok.Top                     := 65;
  36.   ok.Left                    := Width - 95;
  37.   Ok.Kind                    := bkOK;
  38.  
  39.   Result := '';
  40.   if not(aForm.ShowModal = mrCancel) then
  41.     Result := Edit.Text;
  42.   aForm.Free;
  43.  
  44. end;

Happy New Year too!

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Dialog question
« Reply #2 on: January 01, 2021, 09:03:56 am »
That looks just about right.

Thank You
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

jamie

  • Hero Member
  • *****
  • Posts: 6733
Re: Dialog question
« Reply #3 on: January 01, 2021, 02:28:32 pm »
You can also use the IO (Designer) to create a new form for your application, design it all there and configure it to not be visible but auto created so that when you app runs, its not showing..

When you need it then

 if MyASkingForm.ShowModal = mrOk then....

----
 Putting that aside you can also look at the TTaskDialog which should be in the Dialog section.. Its very configurable .

The only true wisdom is knowing you know nothing

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Dialog question
« Reply #4 on: January 01, 2021, 07:27:48 pm »
@Handako

Wow that really worked nice. Thanks

Is there a way to determine the center of the monitor the program is running on. Because I can Left, and top the dialog box it would be possible to show it off form or monitor. 
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Dialog question
« Reply #5 on: January 01, 2021, 08:14:34 pm »
@Jamie

 Is there a way to get a return string value from TTaskDialog like a Pin number . I can't see a way.
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

jamie

  • Hero Member
  • *****
  • Posts: 6733
Re: Dialog question
« Reply #6 on: January 01, 2021, 09:06:18 pm »
yes there is but not easy for you..

I would suggest for you to create a new form and build your form exactly the way you wish.. like I told you..

The TaskDialog out of the box is a prompt type control with lots of options but one thing it does not have out of the box is a EDIT component on it.

its just a simple matter of going to your FILE:Newform
It will start a new empty that becomes part of your project..

Set the property Visible := False so it does not show while you are using your app

 when ready

 do this
 
TheResult := MyNewForm.ShowModal;

Then from there you can test the results or query an edit box on the form that you put there.

 this gives you the best control because you can customize it exactly the way you wish using the designer which make things a lot easier

If you wish I can create a test project for you.

The only true wisdom is knowing you know nothing

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Dialog question
« Reply #7 on: January 01, 2021, 09:58:19 pm »
Is there a way to get a return string value from TTaskDialog like a Pin number . I can't see a way.

While, yes, TTaskDialog is very configurable, its really just an "information" dialog meant to show some info to the user, not to ask her for anything.

What you do have is quite a lot of simple "dialogs" in the Dialogs unit, each more or less specialized in getting some kind info from the user: InputBox, InputCombo, InputQuery, PasswordBox, QuestionDialog, .... and for most of them you just have to do something like, for example:
Code: Pascal  [Select][+][-]
  1. MyString := InputBox('Name', 'Please, enter your name:', '')
which will do basically the same than Handoko's code, though it's not quite as configurable as you wanted.

But since you tried InputQuery I guess you knew it already :-[
« Last Edit: January 01, 2021, 10:01:10 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Dialog question
« Reply #8 on: January 01, 2021, 11:17:15 pm »
Is there a way to determine the center of the monitor the program is running on. Because I can Left, and top the dialog box it would be possible to show it off form or monitor.
If you roll your own dialog (which as Handoko showed is not very difficult)  and want it centred on the screen, simply set its form's Position property to poScreenCenter. You don't need to work out the centre coordinates yourself. Let the LCL do it, and position it for you.

jamie

  • Hero Member
  • *****
  • Posts: 6733
Re: Dialog question
« Reply #9 on: January 02, 2021, 01:42:37 am »
Is there a way to get a return string value from TTaskDialog like a Pin number . I can't see a way.

While, yes, TTaskDialog is very configurable, its really just an "information" dialog meant to show some info to the user, not to ask her for anything.

What you do have is quite a lot of simple "dialogs" in the Dialogs unit, each more or less specialized in getting some kind info from the user: InputBox, InputCombo, InputQuery, PasswordBox, QuestionDialog, .... and for most of them you just have to do something like, for example:
Code: Pascal  [Select][+][-]
  1. MyString := InputBox('Name', 'Please, enter your name:', '')
which will do basically the same than Handoko's code, though it's not quite as configurable as you wanted.

But since you tried InputQuery I guess you knew it already :-[

Yup, I think you nailed it, it can't get much simpler than that..
I see the use the same Dialog for all of them, just slight different configs.

I noticed the box is a little on the wide side, wonder if there is a constant in the dialogs file for that ?
The only true wisdom is knowing you know nothing

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Dialog question
« Reply #10 on: January 02, 2021, 02:00:38 am »
@ All

I have Handoko code running in a demo and  it is just what I need.
 So I put it in my program. I think I did it just like the demo but I get an error. 

unit1.pas(702,10) Error: Identifier not found "RequestInput"

I just put the procedure in the program, No changes. The procedure is not declared under types. The program will compile fine but if I try and call the procedure I get the error.


S1 := RequestInput(550, 650, 105, 'Required', '4 digit Pin');

I would post the code if need be.
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2032
  • Former Delphi 1-7, 10.2 user
Re: Dialog question
« Reply #11 on: January 02, 2021, 03:37:25 am »
Works perfectly for me - project attached. You must have an error in your code.

bytebites

  • Hero Member
  • *****
  • Posts: 680
Re: Dialog question
« Reply #12 on: January 02, 2021, 04:54:39 am »
The function is not visible where you use it.

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Dialog question
« Reply #13 on: January 02, 2021, 05:44:47 am »
Works perfectly for me - project attached. You must have an error in your code.

cocoa_extra.pas(18,2) Fatal: The feature "Objective-C" is not, or not yet, supported on the selected target platform

Get this error on you download.

I'm running Win10 I think you must be on a unix system.
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Dialog question
« Reply #14 on: January 02, 2021, 05:47:53 am »
The function is not visible where you use it.

You are right.

code attached. Can supply data if required.
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

 

TinyPortal © 2005-2018