Object Specifiers (WAS Coerce String to Handler?)
Object Specifiers (WAS Coerce String to Handler?)
- Subject: Object Specifiers (WAS Coerce String to Handler?)
- From: Richard 23 <email@hidden>
- Date: Wed, 18 Apr 2001 03:07:25 -0700
>
> on makereference(propname, target)
sorry if I seem disconnected and redundant here, but I missed a
a detail or two from the earlier bits of this thread, but only
the original post and followup discussion. I caught the rest.
So I'll just toss out how I do it.
A few weeks ago I started assembling a document on the broad
subject of conditional code and got so fed up trying to get
the HTML so it would render equally awfully in both of the
major browsers I tossed it on the pile and moved on.
I noticed this topic was raised so I completed a rough copy of
it. Anyone who'd like to walk through it can take a peek at
<
http://homepage.mac.com/richard23/info/conditionalcode101.html>
Now on with the script:
-- ---------------------------------------------------------
-- Preprocessed by Convert Script 1.0d4
-- ---------------------------------------------------------
-- author: Richard 23, date: Tuesday, April 17, 2001
-- ---------------------------------------------------------
-- Note: in the BuildRef property/handler are the terms
-- key form, key data, desired class... I cheated. I have
-- a custom osax to map codes per Universal Interfaces.
-- use: {<<class form>>, <<class seld>>, <<class want>>.
-- ---------------------------------------------------------
property formName : constant "name"
property formIndx : constant "indx"
property formRele : constant "rele"
property formTest : constant "test"
property formProp : constant "prop"
-- ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. .
script asObj
end script
-- ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. .
-- used as a selector (do I want a reference or a value?)
-- To get a value, call handler through this script object.
-- ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. .
-- ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. .
-- handler built during compile so I don't have to do it
-- ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. .
property BuildRef : run script "f
on f(theForm,theData, theClass, theObj)
if theObj = null then set theObj to it
get <<class obj >> {==>
key form:GetEnum(theForm),==>
key
data:theData, ==>
desired class: GetType(theClass),==>
<<class from>>: theObj}
end f"
-- ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. .
-- a couple of basic object specifiers, by index and named
-- ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. .
-- Each returns a reference (object), to get value instead
-- call through 'asObj', see the example below...
-- ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. .
-- [theData]: property you want to get (class/type code)
-- [theClass]: how d'ya want it...don't beg, it don't help!
-- [theObj]: target process, pass self if no target...
on BuildPropRef(theData, theClass, theObj)
BuildReply(BuildRef(formProp, theData, theClass, theObj))
end BuildPropRef
on BuildIndxRef(theClass, theIdx, theObj)
BuildReply(BuildRef(formIndx, theIdx, theClass, theObj))
end BuildIndxRef
-- ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. .
-- dereferences object spec if called thru asObj
-- ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. ._. .
on BuildReply(theValue)
if it = asObj then
theValue's contents
else
theValue
end if
end BuildReply
-- --=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=
-- Convenience handlers: convert string to type or constant
-- --=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=
on GetEnum(theEnum)
if theEnum's class /= constant then set theEnum ==>
to get constant theEnum as constant
return theEnum
end GetEnum
on GetType(theType)
if theType's class /= class then set theType ==>
to get type class theType as type class
return theType
end GetType
-- ---------------------------------------------------------
-- getting a reference: -- "Finder's 2nd folder"
BuildIndxRef("cfol", 2, application "Finder")
-- getting a value: -- Finder's name
asObj's BuildPropRef("pnam", string, application "Finder")
In both cases of course it's much easier to use terms.
I'll probably do this in C...building specifiers in this way
is about as fun as pulling teeth with a rusty pair of scisors
and nearly as productive.
Time for a primal scream....
That's better.
R23