develop-24 9512 December 1995
From the originals
13 scansMachine-transcribed text and image descriptions. Check the linked original for uncertain words or fine print.
These are transcribed pages from the documents, not the full publications. Open the original for the remaining pages.
PDF page 12
• Iterate over the elements of any token. • Determine class membership of any token. • Compare properties of the elements of any token. • Convert a whose clause into some internal representation usable by your application. The first two operations are required of any scriptable application, so yours probably can already do them. Comparing properties is something your application probably doesn’t do yet, but in the worst case you could always write a few lines of code that call your property object accessor function, retrieve the data from the resulting property token, and then compare the descriptor that was returned. Obviously you can do better than this in terms of performance, and later on we’ll investigate how. First, though, we’ll look at how to interpret the contents of a whose descriptor. THE CONTENTS OF A WHOSE DESCRIPTOR Earlier I claimed that a whose descriptor was an AERecord, but I lied. A whose descriptor is actually a descriptor of type typeWhoseDescriptor. Internally, a whose descriptor is stored just like an AERecord, but you can’t extract its parameters unless you first coerce it to type typeAERecord. In Apple events parlance, this type of descriptor is called a coerced record ; its basic type is typeAERecord, and its coerced type is typeWhoseDescriptor. SPEEDING UP WHOSE CLAUSE RESOLUTION IN YOUR SCRIPTABLE APPLICATION 11 Listing 3. Handling formWhose in the object accessor pascal OSErr MyObjectAccessor(DescType desiredClass, AEDesc container, DescType /*containerClass*/, DescType keyForm, AEDesc keyData, AEDesc* resultToken, long /*hRefCon*/) { switch (keyForm) { // case formAbsolutePosition, and so on ... case formWhose: // TWhoseDescriptor is a class that knows how to interpret // a whose descriptor and test tokens for membership in the // search set defined by the desired class and the whose // descriptor. TWhoseDescriptor whoseDesc(desiredClass, keyData); // TTokenIterator is a class that knows how to iterate // over the elements of a token. TTokenIterator iter(container); for (iter.Reset(); iter.More(); iter.Next()) { AEDesc token = iter.Current(); if (whoseDesc.Compare(token) == kTokenIsInSearchSet) { // Add token to the collection stored in resultToken. AddTokenToResult(token, resultToken); } } break; } return noErr; }
- Languages
- English