Apple Newton Utilities Uživatelská příručka Strana 415

  • Stažení
  • Přidat do mých příruček
  • Tisk
  • Strana
    / 942
  • Tabulka s obsahem
  • KNIHY
  • Hodnocené. / 5. Na základě hodnocení zákazníků
Zobrazit stránku 414
CHAPTER 10
Recognition: Advanced Topics
Using Advanced Topics in Recognition 10-39
The cells in this example template use lters dened by the format and filters
slots to restrict input to valid values.
The
format slot species 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 rst position in the comb view is ltered by the element 1 of the
filters
array, which is the
digits1 template; the second position is ltered by element 0
of the lters 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 eld 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 dene a
CleanupString function that
examines the input string and indicates an error condition or modies 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,
};
Zobrazit stránku 414
1 2 ... 410 411 412 413 414 415 416 417 418 419 420 ... 941 942

Komentáře k této Příručce

Žádné komentáře