
CHAPTER 10
Recognition: Advanced Topics
Using Advanced Topics in Recognition 10-39
The cells in this example template use filters defined by the format and filters
slots to restrict input to valid values.
The
format slot specifies the valid input for each position in the comb view. Each
character in the
format string is an index into the filters array. In this example,
the first position in the comb view is filtered by the element 1 of the
filters
array, which is the
digits1 template; the second position is filtered by element 0
of the filters array, which is the
digits template.
You can write-protect any position in the comb view by placing an underscore (
_)
in the appropriate position in the
format string. In this example, the string positions
that display slashes between the digits of the date field do not allow input. These
are indicated by the underscores at corresponding positions in the
format string.
The
text slot is not used by protoCharEdit views, but may be used as a
default value by optional
SetupString and CleanupString methods that your
template supplies.
Note that the template itself does not restrict any values unnecessarily. For example,
it is not wise to restrict date values according to the value of the month, because the
user might enter the date before the month or the month value might not be
recognized correctly. Instead, you can define a
CleanupString function that
examines the input string and indicates an error condition or modifies the string.
The following code fragment provides examples of typical
SetupString and
CleanupString functions.
myTemplate := {
format:"0000001",
string:" 0",
filters: [kMyDigitsOrSpace, kMyDigits],
SetupString: func(str) begin
// pad string to 5 digits
if StrLen(str) < 7 then
StrMunger(str,0,0,string,0,7-StrLen(str));
str;
end,
CleanupString: func(str) begin
// replace spaces with zeros
StrReplace(str, " ", "0", nil);
// trim leading zeros
str := NumberStr(StringToNumber(str));
str;
end,
};
Komentáře k této Příručce