OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
owl::TValidator Class Reference

A streamable class, TValidator defines an abstract data validation object. More...

#include <owl/validate.h>

Inheritance diagram for owl::TValidator:
owl::TStreamableBase owl::TFilterValidator owl::TLookupValidator owl::TPXPictureValidator owl::TRangeValidator owl::TStringLookupValidator

Public Member Functions

 TValidator ()
 Constructs an abstract validator object and sets Options fields to 0.
 
virtual ~TValidator ()
 Destroys an abstract validator object.
 
virtual void Error (TWindow *owner)
 Error is an abstract function called by Valid when it detects that the user has entered invalid information.
 
virtual bool IsValidInput (TCHAR *input, bool suppressFill)
 Checks current input against validator.
 
virtual bool IsValid (LPCTSTR input)
 Checks input against validator for completeness. Never modifies input.
 
virtual uint Transfer (TCHAR *text, void *buffer, TTransferDirection direction)
 Allows a validator to set and read the values of its associated edit control.
 
virtual int Adjust (tstring &text, int &begPos, int &endPos, int amount)
 Adjusts the 'value' of the text, given a cursor position and an amount.
 
bool Valid (LPCTSTR str, TWindow *owner=0)
 Returns true if IsValid returns true.
 
bool Valid (const tstring &str, TWindow *owner=0)
 
bool HasOption (int option)
 Gets the Options bits. Returns true if a specified option is set.
 
void SetOption (int option)
 Sets the bits for the Options data member.
 
void UnsetOption (int option)
 Unsets the bits specified in the Options data member.
 
- Public Member Functions inherited from owl::TStreamableBase
virtual ~TStreamableBase ()
 

Protected Attributes

uint16 Options
 A bitmap member used to control options for various descendants of TValidator.
 

Detailed Description

A streamable class, TValidator defines an abstract data validation object.

Although you will never actually create an instance of TValidator, it provides the abstract functions for the other data validation objects.

The VALIDATE.CPP sample program on BC5.0x distribution disk derives TValidateApp from TApplication in the following manner:

class TValidateApp : public TApplication {
public:
TValidateApp() : TApplication("ValidateApp") { }
void InitMainWindow() {
MainWindow = new TTestWindow(0, "Validate Dialog Input");
}
Derived from TModule and TMsgThread and virtually derived from TEventHandler, TApplication acts as an...
Definition applicat.h:141

The program displays the following message box if the user enters an invalid employee ID:

Definition at line 71 of file validate.h.

Constructor & Destructor Documentation

◆ TValidator()

owl::TValidator::TValidator ( )

Constructs an abstract validator object and sets Options fields to 0.

Definition at line 24 of file validate.cpp.

References Options.

◆ ~TValidator()

owl::TValidator::~TValidator ( )
virtual

Destroys an abstract validator object.

Definition at line 32 of file validate.cpp.

Member Function Documentation

◆ Adjust()

int owl::TValidator::Adjust ( tstring & text,
int & begPos,
int & endPos,
int amount )
virtual

Adjusts the 'value' of the text, given a cursor position and an amount.

Returns the actual amount adjusted.

Reimplemented in owl::TPXPictureValidator, owl::TRangeValidator, and owl::TStringLookupValidator.

Definition at line 125 of file validate.cpp.

◆ Error()

void owl::TValidator::Error ( TWindow * owner)
virtual

Error is an abstract function called by Valid when it detects that the user has entered invalid information.

By default, TValidator::Error does nothing, but derived classes can override Error to provide feedback to the user.

Reimplemented in owl::TPXPictureValidator, owl::TFilterValidator, owl::TRangeValidator, and owl::TStringLookupValidator.

Definition at line 42 of file validate.cpp.

◆ HasOption()

bool owl::TValidator::HasOption ( int option)
inline

Gets the Options bits. Returns true if a specified option is set.

Definition at line 356 of file validate.h.

◆ IsValid()

bool owl::TValidator::IsValid ( LPCTSTR input)
virtual

Checks input against validator for completeness. Never modifies input.

By default, returns true. Derived validator classes can override IsValid to validate data for a completed edit control. If an edit control has an associated validator object, and the edit control's IsValid method is called with its reportErr parameter set to true, then the validator object's Valid method, which in turn calls IsValid, is called to determine whether the contents of the edit control are valid. If the edit control's IsValid method is called with the reportErr parameter set to false, then the validator's IsValid method is called directly.

Reimplemented in owl::TPXPictureValidator, owl::TFilterValidator, owl::TRangeValidator, and owl::TLookupValidator.

Definition at line 87 of file validate.cpp.

◆ IsValidInput()

bool owl::TValidator::IsValidInput ( TCHAR * input,
bool suppressFill )
virtual

Checks current input against validator.

May adjust input if suppressFill isn't set & validator has the voFill option set. If an edit control has an associated validator object, it calls IsValidInput after processing each keyboard event, thus giving validators such as filter validators an opportunity to catch errors before the user fills the entire item or screen. By default, IsValidInput returns true. Derived data validators can override IsValidInput to validate data as the user types it, returning true if str holds valid data and false otherwise. str is the current input string. suppressFill determines whether the validator should automatically format the string before validating it. If suppressFill is true, validation takes place on the unmodified string str. If suppressFill is false, the validator should apply any filling or padding before validating data. Of the standard validator objects, only TPXPictureValidator checks suppressFill. IsValidInput can modify the contents of the input string; for example, it can force characters to uppercase or insert literal characters from a format picture. IsValidInput should not, however, delete invalid characters from the string. By returning false, IsValidInput indicates that the edit control should erase the incorrect characters.

Reimplemented in owl::TPXPictureValidator, and owl::TFilterValidator.

Definition at line 69 of file validate.cpp.

◆ SetOption()

void owl::TValidator::SetOption ( int option)
inline

Sets the bits for the Options data member.

Definition at line 364 of file validate.h.

◆ Transfer()

uint owl::TValidator::Transfer ( TCHAR * text,
void * buffer,
TTransferDirection direction )
virtual

Allows a validator to set and read the values of its associated edit control.

This is primarily useful for validators that check non-string data, such as numeric values. For example, TRangeValidator uses Transfer to read and write values instead of transferring an entire string. By default, edit controls with validators give the validator the first chance to respond to DataSize, GetData, and SetData by calling the validator's Transfer method. If Transfer returns anything other than 0, it indicates to the edit control that it has handled the appropriate transfer. The default action of TValidator::Transfer is always to return 0. If you want the validator to transfer data, you must override its Transfer method. Transfer's first two parameters are the associated edit control's text string and the tdGetData or tdSetData data record. Depending on the value of direction, Transfer can set str from buffer or read the data from str into buffer. The return value is always the number of bytes transferred. If direction is tdSizeData, Transfer doesn't change either str or buffer; it just returns the data size. If direction is tdSetData, Transfer reads the appropriate number of bytes from buffer, converts them into the proper string form, and sets them into str, returning the number of bytes read. If direction is tdGetData, Transfer converts str into the appropriate data type and writes the value into buffer, returning the number of bytes written.

Reimplemented in owl::TRangeValidator.

Definition at line 115 of file validate.cpp.

◆ UnsetOption()

void owl::TValidator::UnsetOption ( int option)
inline

Unsets the bits specified in the Options data member.

Definition at line 372 of file validate.h.

◆ Valid() [1/2]

bool owl::TValidator::Valid ( const tstring & str,
TWindow * owner = 0 )
inline

Definition at line 86 of file validate.h.

References Valid().

◆ Valid() [2/2]

bool owl::TValidator::Valid ( LPCTSTR str,
TWindow * owner = 0 )
inline

Returns true if IsValid returns true.

Otherwise, calls Error and returns false. A validator's Valid method is called by the IsValid method of its associated edit control. Edit controls with associated validator objects call the validator's Valid method under two conditions. The first condition is when the edit control's IsValid method is called with the reportErr parameter set to true. The second condition is when the dialog box that contains the edit control calls Valid for all its controls, usually because the user requested to close the dialog box or to accept an entry screen.

Definition at line 344 of file validate.h.

Member Data Documentation

◆ Options

uint16 owl::TValidator::Options
protected

A bitmap member used to control options for various descendants of TValidator.

By default, the TValidator constructor clears all the bits in Options.

Definition at line 94 of file validate.h.


The documentation for this class was generated from the following files: