Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>François is right. You've reached the limit of the tool you've been given. <a href="http://docwiki.embarcadero.com/VCL/en/Dialogs.InputBox" rel="nofollow noreferrer"><code>InputBox</code></a> simply isn't designed for complex input, and it's not designed to be extended to handle multiple values, either.</p> <p><a href="http://www.delphipages.com/forum/showthread.php?t=154839" rel="nofollow noreferrer">The page you linked to</a> in your comment has an example, but it's presented rather poorly, so I don't blame you for misunderstanding it. It took me a few reads to get, too. At its core is the <code>MyAsk</code> function at the bottom. (Ignore the <code>TAppendThread</code> class declaration at the top. It's useless.) <code>MyAsk</code> accepts a list of records with with prompts and values, and for each record, it calls <code>InputBox</code> to request a value from the user. It might be easier to understand without the record. It could be rewritten like this:</p> <pre><code>procedure MultiInputBox(const Prompts: array of string; var Values: array of string]); var i: Integer; begin Assert(Length(Prompts) = Length(Values)); for i := 0 to High(Prompts) do begin Values[i] := InputBox(Application.Title, Prompts[i], Values[i]); end; end; </code></pre> <p>Call it like this:</p> <pre><code>TempTime := TimeToStr(DefaultTime); TempPressure := IntToStr(DefaultPressure); TempName := DefaultName; MultiInputBox(['Time', 'Pressure', 'Name'], [TempTime, TempPressure, TempName]); TimeToUse := StrToTime(TempTime); PressureToUse := StrToInt(TempPressure); NameToUse := TempName; </code></pre> <p>That's a <em>terrible</em> interface for the user, though. There's no way to go back, there's no way to cancel, there's no indication of how long the interrogation is going to last, and there's no way to enforce formats for certain data types. You'll really be much better off if you design a custom form that gets exactly the information you need. You're using a tool that makes designing a form about the easiest thing in the world. Don't resist that.</p> <p>If you need to get the time, the pressure, and the name, then make a form with three input controls. Use a <a href="http://docwiki.embarcadero.com/VCL/en/ComCtrls.TDateTimePicker" rel="nofollow noreferrer"><code>TDateTimePicker</code></a> for the time, consider a <a href="http://docwiki.embarcadero.com/VCL/en/Spin.TSpinEdit" rel="nofollow noreferrer"><code>TSpinEdit</code></a> for the numeric input, and use a <a href="http://docwiki.embarcadero.com/VCL/en/StdCtrls.TEdit" rel="nofollow noreferrer"><code>TEdit</code></a> for the name. Put <code>TLabel</code> controls next to each input so the user knows what each one is for. Put OK and Cancel buttons on the form. Set various other form properties, such as the border style and the caption. There's almost <em>no code</em> to write in that form. You're free to add code to validate the input values, though, to make sure they make sense.</p> <p>To use it, simply create it, populate its initial values, show it modally, and read the new values out when it closes.</p> <pre><code>var form: TDatePressureNameDialog; begin form := TDatePressureNameDialog.Create(nil); try form.TimePicker.Value := DefaultTime; form.PressureEdit.Value := DefaultPressure; form.NameEdit.Text := DefaultName; if form.ShowModal = mrOK then begin TimeToUse := Frac(form.TimePicker.Value); PressureToUse := form.PressureEdit.Value; NameToUse := form.NameEdit.Text; end; finally form.Free; end; end; </code></pre> <p>Notice also how I check the result of the <a href="http://docwiki.embarcadero.com/VCL/en/Forms.TCustomForm.ShowModal" rel="nofollow noreferrer"><code>ShowModal</code></a> method. That lets you know whether the user pressed OK or Cancel to close the form. You can't do that with <code>InputBox</code>, which always returns a string. (<a href="http://docwiki.embarcadero.com/VCL/en/Dialogs.InputQuery" rel="nofollow noreferrer"><code>InputQuery</code></a> can tell you that information, which is the primary difference between those two functions, but that alone doesn't really make either function worth using in your situation.)</p> <p>Don't worry about this new form class weighing down your project. The two things that have the biggest impact on project size are the <em>SysUtils</em> and <em>Forms</em> units. You've already included those, so the worst of it is already past. Adding a form to a project that already has at least one form doesn't affect the project size much at all, especially not the form I described above, which only has eight controls.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload