Class TRbwDataEntry

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type TRbwDataEntry = class(TEdit)

Description

TRbwDataEntry provides data checking for user-entered data.

All data entered in a TRbwDataEntry is first checked to be sure it can be converted to another type of data as specified by the DataType property. In the event that the data can not be converted, characters will be stripped from the end of Text until the conversion is possible. If the DataType is dtInteger or dtReal, it is also possible to check that the numeric representation of Text does not lie outside the range Min..Max. Use CheckMin and CheckMax to turn on or off range checking. OnExceedingBounds and OnExceededBounds can be used to provide custom handling for cases where the data do lie outside the range specified by Min..Max when range checking is on.

Hierarchy

Overview

Fields

Private FOutput: string;
Private FDataType: TDataType;
Private FMax: extended;
Private FMin: extended;
Private FCheckMax: boolean;
Private FCheckMin: boolean;
Private FOnDataTypeChanged: TNotifyEvent;
Private FOnExceededBounds: TNotifyEvent;
Private FOnExceedingBounds: TNotifyEvent;

Methods

Private procedure LocalizeString(var ANumberString: string; var ChangedDecimalPosition: integer);
Private function ReadOutput: string;
Private function LocalStrToFloat(const S: string): Extended;
Private procedure SetDataType(ADataType: TDataType);
Protected function GetText: TCaption; override;
Protected procedure Loaded; override;
Protected procedure SetText(const Value: TCaption); override;
Protected procedure SetMax(Value: extended); virtual;
Protected procedure SetMin(Value: extended); virtual;
Protected procedure SetCheckMax(Value: boolean); virtual;
Protected procedure SetCheckMin(Value: boolean); virtual;
Protected procedure DoExit; override;
Protected procedure Change; override;
Protected procedure DataTypeChanged; dynamic;
Protected procedure ExceedingBounds; dynamic;
Protected procedure ExceededBounds; dynamic;
Protected procedure TextChanged; override;
Protected function ChangeTextToInteger(var FirstInvalidPosition: integer): string; virtual;
Protected function ChangeTextToReal(var FirstInvalidPosition: integer): string; virtual;
Public constructor Create(AOwner: TComponent); override;
Public procedure CheckRange; virtual;

Properties

Published property DataType: TDataType read FDataType write SetDataType default dtString;
Published property Max: extended read FMax write SetMax;
Published property Min: extended read FMin write SetMin;
Published property CheckMax: boolean read FCheckMax write SetCheckMax default False;
Published property CheckMin: boolean read FCheckMin write SetCheckMin default False;
Published property Output: string read ReadOutput;
Published property Text: TCaption read GetText write SetText;
Published property OnDataTypeChanged: TNotifyEvent read FOnDataTypeChanged write FOnDataTypeChanged;
Published property OnExceededBounds: TNotifyEvent read FOnExceededBounds write FOnExceededBounds;
Published property OnExceedingBounds: TNotifyEvent read FOnExceedingBounds write FOnExceedingBounds;

Description

Fields

Private FOutput: string;

FOutput: string; See Output.

Private FDataType: TDataType;

FDataType: TDataType; See DataType.

Private FMax: extended;

FMax: extended; See Max.

Private FMin: extended;

FMin: extended; See Min.

Private FCheckMax: boolean;

FCheckMax: boolean; See CheckMax.

Private FCheckMin: boolean;

FCheckMin: boolean; See CheckMin.

Private FOnDataTypeChanged: TNotifyEvent;

FOnDataTypeChanged: TNotifyEvent; See OnDataTypeChanged.

Private FOnExceededBounds: TNotifyEvent;

FOnExceededBounds: TNotifyEvent; See OnExceededBounds.

Private FOnExceedingBounds: TNotifyEvent;

FOnExceedingBounds: TNotifyEvent; See OnExceedingBounds.

Methods

Private procedure LocalizeString(var ANumberString: string; var ChangedDecimalPosition: integer);

If the decimal character is a period, the first comma in ANumberString is changed to a period. If the decimal character is a comma, the first period in ANumberString is changed to a comma. If a period or comma is changed, ChangedDecimalPosition is set to the position that changed.

Private function ReadOutput: string;

ReadOutput is a string representation of the value represented by Text in which the decimal separator is always a period.

Private function LocalStrToFloat(const S: string): Extended;

LocalStrToFloat converts Text to a real number.

Private procedure SetDataType(ADataType: TDataType);

See DataType.

Protected function GetText: TCaption; override;

See Text.

Protected procedure Loaded; override;

Loaded updates the Text property.

Protected procedure SetText(const Value: TCaption); override;

See Text.

Protected procedure SetMax(Value: extended); virtual;

SetMax sets the DataType property. It also changes the text to make sure it is consistent with the DataType and updates Output to be consistent with Text. Items[0] and Items[1] are reset to 'False' and 'True' respectively every time the DataType is set to dtBoolean. procedure SetDataType(ADataType: TDataType); virtual; {SetMax changes Max and then calls CheckRange

Protected procedure SetMin(Value: extended); virtual;

SetMin changes Min and then calls CheckRange

Protected procedure SetCheckMax(Value: boolean); virtual;

SetCheckMax changes CheckMax and then if CheckMax is true calls CheckRange

Protected procedure SetCheckMin(Value: boolean); virtual;

SetCheckMin changes CheckMin and then if CheckMax is true calls CheckRange

Protected procedure DoExit; override;

DoExit calls the OnExit event; It calls the inherited method and then CheckRange. See DoExit

Protected procedure Change; override;

Change calls the OnChange event; It calls the inherited method and then TextChanged.

Protected procedure DataTypeChanged; dynamic;

DataTypeChanged calls the OnDataTypeChanged event;

Protected procedure ExceedingBounds; dynamic;

ExceedingBounds calls the OnExceedingBounds event;

Protected procedure ExceededBounds; dynamic;

ExceededBounds calls the OnExceededBounds event;

Protected procedure TextChanged; override;

TextChanged is called before the event handler for the OnChanged event. It checks that the data entered in the TRbwDataEntry is valid. It does not reject '-' even though that is not a valid integer or real number. However, if the text is '-' when OnExit occurs, the CheckRange procedure will catch the error.

Protected function ChangeTextToInteger(var FirstInvalidPosition: integer): string; virtual;

ChangeTextToInteger takes the string in the Text property and attempts to convert it to an integer. If it fails, it strips one character at a time from the end of Text until it does succeed. It converts '' to '0'. The end result is a string that can be converted to an integer.

Protected function ChangeTextToReal(var FirstInvalidPosition: integer): string; virtual;

ChangeTextToReal takes the string in the Text property and attempts to convert it to an extended real number. If it fails, it strips one character at a time from the end of Text until it does succeed. It converts '' to '0'. The end result is a string that can be converted to an real number.

Public constructor Create(AOwner: TComponent); override;

Create creates and initializes a TRbwDataEntry instance.

Public procedure CheckRange; virtual;

CheckRange is called before the event handler for the OnExit event. It checks that the data in the TRbwDataEntry do not exceed the specified limits. However, it only checks the range if the DataType is dtInteger or dtReal. It also catches the invalid value of '-' for real and integer data typed in the Text field. If the value in the data field should be checked as specified by CheckMin and CheckMax and is outside the limits set by Min and Max an OnExceedingBounds event occurs. If after the event handler for OnExceedingBounds, the numeric representation of Text is still outside the appropriate range, Text will be changed to Max or Min, whichever is closer and calls the OnExceededBounds event.

Properties

Published property DataType: TDataType read FDataType write SetDataType default dtString;

Set the DataType to an appropriate value to cause the TRbwDataEntry to check that user-entered data is the a ppropriate type.

Published property Max: extended read FMax write SetMax;

If CheckMax is true and the DataType is dtInteger or dtReal, the TRbwDataEntry will check the data entered and change it to Max if the entered value is larger than Max. It will also beep and set the focus to the TRbwDataEntry. To modify this behaviour, you can use the OnExceedingBounds or OnExceededBounds events.

Published property Min: extended read FMin write SetMin;

If CheckMin is true and the DataType is dtInteger or dtReal, the TRbwDataEntry will check the data entered and change it to Min if the entered value is smaller than Min. It will also beep and set the focus to the TRbwDataEntry. To modify this behaviour, you can use the OnExceedingBounds or OnExceededBounds events.

Published property CheckMax: boolean read FCheckMax write SetCheckMax default False;

If CheckMax is true and the DataType is dtInteger or dtReal, the TRbwDataEntry will check the data entered and change it to Max if the entered value is larger than Max. It will also beep and set the focus to the TRbwDataEntry. To modify this behaviour, you can use the OnExceedingBounds or OnExceededBounds events.

Published property CheckMin: boolean read FCheckMin write SetCheckMin default False;

If CheckMin is true and the DataType is dtInteger or dtReal, the TRbwDataEntry will check the data entered and change it to Min if the entered value is smaller than Min. It will also beep and set the focus to the TRbwDataEntry. To modify this behaviour, you can use the OnExceedingBounds or OnExceededBounds events.

Published property Output: string read ReadOutput;

If the DataType is anything other than dtBoolean, Output will be the same as Text. For dtBoolean, Output is '0' if Text is 'False' and '1' if Text is 'True'. Output is read-only. Output always uses '.' as the decimal separator.

Published property Text: TCaption read GetText write SetText;

Text is the text that is displayed. Text is identical to original Text property except that setting the text generates an OnChange Event.

Published property OnDataTypeChanged: TNotifyEvent read FOnDataTypeChanged write FOnDataTypeChanged;

Whenever the DataType Property is changed, an OnDataTypeChanged event occurs.

Published property OnExceededBounds: TNotifyEvent read FOnExceededBounds write FOnExceededBounds;

An OnExceededBounds event occurs if 1. the DataType is dtInteger or dtReal and either 2. CheckMax is true and the numeric representation of the Text Property exceeds the Max Property or 3. CheckMin is true and the numeric representation of the Text Property is less than the Min Property. OnExceededBounds occurs after the default handling of such cases has occurred. CheckRange will be called again after your event handler. Be careful that your custom handling does not result in an infinite loop.

Published property OnExceedingBounds: TNotifyEvent read FOnExceedingBounds write FOnExceedingBounds;

An OnExceedingBounds event occurs in the CheckRange procedure if 1. the DataType is dtInteger or dtReal and either 2. CheckMax is true and the numeric representation of the Text Property exceeds the Max Property or 3. CheckMin is true and the numeric representation of the Text Property is less than the Min Property. OnExceedingBounds provides an opportunity for custom handling of such cases before they have been handled automatically. CheckRange will be called again after your event handler. Be careful that your custom handling does not result in an infinite loop.


Generated by PasDoc 0.10.0 on 2006-10-31 09:56:32