IntInput
is a Turbo Vision module that provides a custom input field for integer values with specified ranges. It extends the standard input line component to validate and handle integer input, ensuring the values fall within defined intervals.
- Interval: An enumerated type representing the range intervals:
a_b
: [min, max]a_inf
: [min, ∞)inf_b
: (-∞, max]inf_inf
: (-∞, ∞)
-
Fields:
min
: The minimum value of the range.max
: The maximum value of the range.int
: The type of interval.
-
Constructor:
Init(R: TRect; i: integer; mina, maxa: longint)
: Initializes the input line with specified rectangleR
, max lengthi
, minimum valuemina
, and maximum valuemaxa
.
-
Methods:
DataSize: word
: Returns the size of the data.GetData(var Rec)
: Retrieves the integer data from the input field.SetData(var Rec)
: Sets the input field with the provided integer data.Valid(com: word): boolean
: Validates the input data against the defined range.
The IntegerInput
program demonstrates the usage of the TInputInt
object. It presents a dialog to the user for entering an integer within the specified range of -100 to 100.
- Methods:
Run
: Executes the main functionality by showing the integer input dialog.HandleEvent(var Event: TEvent)
: Handles application events, triggering the integer input dialog on a new command.ShowDateDialog
: Displays the dialog for entering an integer.
- Initializes and runs an instance of
TMyApp
, showing the dialog for integer input and validating the input against the specified range.
-
Integration:
- Include
IntInput
in your uses clause. - Create an instance of
TInputInt
and initialize it with the desired range. - Use
GetData
andSetData
to interact with the input value. - Ensure
Valid
is called to validate the input.
- Include
-
Example:
- The provided example in
IntegerInput
shows a dialog for inputting an integer within the range of -100 to 100.
- The provided example in
- Displays error messages for invalid inputs, such as non-integer values or values outside the specified range, using message boxes.
- The module depends on standard Pascal units such as
Objects
,Views
,Dialogs
, andMsgBox
.