Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

TPXPictureValidator Class Reference

Compare user input with a picture of a data format to determine the validity of entered data. More...

#include <validate.h>

Inheritance diagram for TPXPictureValidator::

TValidator TObject TStreamable List of all members.

Public Methods

 TPXPictureValidator (const char *aPic, Boolean autoFill)
 ~TPXPictureValidator ()
virtual void error ()
virtual Boolean isValidInput (char *s, Boolean suppressFill)
virtual Boolean isValid (const char *s)
virtual TPicResult picture (char *input, Boolean autoFill)

Static Public Methods

TStreamablebuild ()

Static Public Attributes

const char* const name

Protected Methods

 TPXPictureValidator (StreamableInit)
virtual void write (opstream &os)
virtual void* read (ipstream &is)

Protected Attributes

char* pic

Detailed Description

Picture validator objects compare user input with a picture of a data format to determine the validity of entered data. The pictures are compatible with the pictures Borland's Paradox relational database uses to control data entry.

For a complete description of picture specifiers see method TPXPictureValidator::picture()

Definition at line 254 of file validate.h.


Constructor & Destructor Documentation

TPXPictureValidator::TPXPictureValidator ( const char * aPic,
Boolean autoFill )
 

Constructs a picture validator object by first calling the constructor inherited from TValidator, then allocating a copy of `aPic' on the heap and setting pic data member to point to it, then setting the voFill bit in TValidator::options data member if `autoFill' is True.

TPXPictureValidator::~TPXPictureValidator ( )
 

Disposes of the string pointed to by pic data member, then disposes of the picture validator object by calling the destructor inherited from TValidator.

TPXPictureValidator::TPXPictureValidator ( StreamableInit ) [protected]
 

Each streamable class needs a "builder" to allocate the correct memory for its objects together with the initialized virtual table pointers. This is achieved by calling this constructor with an argument of type StreamableInit.


Member Function Documentation

TStreamable * TPXPictureValidator::build ( ) [static]
 

Called to create an object in certain stream-reading situations.

Reimplemented from TValidator.

void TPXPictureValidator::error ( ) [virtual]
 

Displays a message box indicating an error in the picture format, displaying the string pointed to by pic data member.

Reimplemented from TValidator.

Boolean TPXPictureValidator::isValid ( const char * s ) [virtual]
 

Compares the string passed in `s' with the format picture specified in pic data member and returns True if pic is null or if picture() returns prComplete for `s', indicating that `s' needs no further input to meet the specified format.

Reimplemented from TValidator.

Boolean TPXPictureValidator::isValidInput ( char * s,
Boolean suppressFill ) [virtual]
 

Checks the string passed in `s' against the format picture specified in pic data member and returns True if pic is null or picture() does not return prError for `s'; otherwise returns False.

The `suppressFill' parameter overrides the value in voFill for the duration of the call to isValidInput().

`s' is a pointer to string, so isValidInput() can modify its value. For example, if `suppressFill' is False and voFill is set, the call to picture() returns a filled string based on `s', so the image in the input line automatically reflects the format specified in pic.

Reimplemented from TValidator.

TPicResult TPXPictureValidator::picture ( char * input,
Boolean autoFill ) [virtual]
 

Formats the string passed in `input' according to the format specified by the picture string pointed to by pic data member. Returns prError if there is an error in the picture string or if `input' contains data that cannot fit the specified picture.

Returns prComplete if `input' can fully satisfy the specifed picture. Returns prIncomplete if `input' contains data that fits the specified picture but not completely.

The following table shows the characters used in creating format pictures.

 Type of character Character Description

 Special           #         Accept only a digit
                   ?         Accept only a letter (case-insensitive)
                   &         Accept only a letter, force to  uppercase
                   @         Accept any character
                   !         Accept any character, force to uppercase

 Match             ;         Take next character literally
                   *         Repetition count
                   []        Option
                   {}        Grouping operators
                   ,         Set of alternatives

 All others                  Taken literally
 

Here are some advanced pictures, which show the power of TPXPictureValidator; these examples come from an old Pascal FAQ written by Berend de Boer, <berend@beard.nest.nl>.

 Name           Value                Description

 UnsignedPic1   #[#][#]*{[;,]###}    unsigned int with optional commas
 UnsignedPic2   #[#][#]*{;,###}      unsigned int with commas
 SignedPic1     [-]#[#][#]*{[;,]###} signed int with optional commas
 SignedPic2     [-]#[#][#]*{;,###}   signed int with commas
 MoneyPic1      [$]*#.{##,00}        dollars, with comma and optinal dollar sign
 MoneyPic2      $*#{.##,.00}         dollars, with comma and dollar sign
 DatePic1       #[#]/#[#]/##         date with 2 digit year (dd/mm/yy or mm/dd/yy)
 DatePic2       #[#]/#[#]/##[##]     date with 2 or 4 digit year (mm/dd/yy or mm/dd/yyyy)
 DatePic3       #[#]/#[#]/####       date with 4 digit year (mm/dd/yyyy)
 TimePic1       {##}:{##}[:{##}]     HH:MM:SS with optional seconds
 TimePic2       {##}:{##}:{##}       HH:MM:SS
 PhonePic1      [(###) ]###-####     phone number with optional area code
 PhonePic2      (###) ###-####       phone number with area code
 SSNPic         ###-##-####
 FirstCharUpPic *{&*? }              uppercase the first char of every word
 FilenamePic    {&*7[&]}.{*3[&]}     filename (no path) with extension
 

Note the *7 and *3 in this last example. A number after a `*' says how many times the next sequence should be repeated; uncovered in the manuals. But this example is not completely correct (is this a bug?), because the `*' is interpreted as that there should be exactly 8 characters! No more, no less. Correct is:

 FilenamePic    {&[&][&][&][&][&][&][&]}.{[&][&][&]}
 

The following examples were given by Sean Wenzel in the Borland Turbo Vision forum on CompuServe:

  • US Phone with optional area code: [(*3{#})]*3{#}-*4{#}
  • Colors with autofill-in: {Red,Gr{ay,een},B{l{ack,ue},rown},White,Yellow}
  • A date in the format "Jan, 31, 1999" with auto fill-in: {J{AN ,U{N ,L }},FEB ,MA{R ,Y },A{PR ,UG },SEP ,OCT ,NOV ,DEC} {1[#],2[#],30,31,#};, 19##
Finally, here my solution for a real validator, for the format "1.234E-6" or "3.14159":

[-]#[*#][[.]#[*#]][E[-]#[#]]

void * TPXPictureValidator::read ( ipstream & is ) [protected, virtual]
 

Reads from the input stream `is'.

Reimplemented from TValidator.

void TPXPictureValidator::write ( opstream & os ) [protected, virtual]
 

Writes to the output stream `os'.

Reimplemented from TValidator.


Member Data Documentation

const char *const TPXPictureValidator::name [static]
 

Undocumented.

Reimplemented from TValidator.

Definition at line 459 of file validate.h.

char * TPXPictureValidator::pic [protected]
 

Points to a string containing the picture that specifies the format for data in the associated input line. The constructor sets pic to the string passed as one of its parameters.

Definition at line 401 of file validate.h.


The documentation for this class was generated from the following file:
Generated at Sat Sep 22 20:19:32 2001 for TVision by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001