RE: interesting discovery (trying to get record labels as strings )
RE: interesting discovery (trying to get record labels as strings )
- Subject: RE: interesting discovery (trying to get record labels as strings )
- From: has <email@hidden>
- Date: Tue, 4 Dec 2001 21:55:46 +0000
Hi,
>
> Olof, I'm curious as to why the above is as complex as it is - is there a
>
> reason for this? The following also works, and is somewhat shorter:
>
>
>
> to extract_exact_usrf(theRecord, fieldName)
>
> run script "on run{r}
>
> return |" & fieldName & "| of r
>
> end" with parameters {theRecord}
>
> end extract_exact_usrf
>
>
>
> extract_exact_usrf({|EU|:3, b:2}, "EU")
>
> --> 3
>
>
>
Because I didn't think to try the 'with parameters' option of 'run script'
>
as a way of getting the record inside a dynamically generated script object.
>
This version is indeed much nicer.
Ahh, that'll be why then.:)
As for assigning handlers to stuff, try the following for your amusement:
======================================================================
on bob(x)
return "I'm Bob. " & x
end bob
on mary(x)
return "I'm Mary. " & x
end mary
on joe(x)
return "I'm Joe. " & x
end joe
property everybody : {bob, mary, joe}
property whoToSpeakTo : {}
set indexNumber to (display dialog "Enter a number between 1 and 3
" default answer "")'s text returned as integer
set whoToSpeakTo to everybody's item indexNumber
whoToSpeakTo("Pleased to meet you.")
--Enter: 1
--> "I'm Bob. Pleased to meet you."
--Enter: 2
--> "I'm Mary. Pleased to meet you."
--Enter: 3
--> "I'm Joe. Pleased to meet you."
======================================================================
At some point during my Adventures With Objects (aka My Forty Days in the
Wilderness), I finally realised that:
on bob...
or:
script bob...
actually means much the same as:
property bob : ...
Heck, you could just _hear_ that penny drop.;)
...
Mind you, I realised this of script objects before I worked out that the
same thing was true of handlers. I think that with handlers it's easy to
get misled by the presence of a pair of parentheses containing a bunch of
parameters. Except you can have a bit of fun with those too...
on beepMe()
beep
end
set x to beepMe
x
--> +handler beepMe;
Or:
on beepMe()
beep
end
set x to beepMe
x()
-- the darn thing beeps!
Not to mention:
on beepMe()
beep
end
set x to beepMe()
x
-- again, the darn thing beeps!
And yet, I can't help thinking that maybe there's even more fun and games
to be had with this sort of thing. e.g. Go take a shufti at strftimeLib now
that it's on AppleMods if you want to see an application of such fun and
games - I honestly don't know if the method used there is faster than if
I'd used one huge if...elseif...elseif... statement, but I did get a kick
out of trying a different approach just to see if it could be done.:)
And then, of course, came:
======================================================================
on getRecordValue(theRecord, theLabel)
do script "
script
on thHndlr(param)
" & cnvt's cnvtObjectToLabel(theLabel) & " of param
end thHndlr
end script"
result's thHndlr(theRecord)
end getRecordValue
======================================================================
and I was totally away with it. Actually, the above is really quite similar
in concept to your original, but in a more rarified form (not that I even
realised the similarity till much later<g>). If it weren't for "do
script"'s inability to pass parameters I'd probably never have realised
half of this, but it forced me to spend quite a bit of time playing with
objects to find a suitable workaround and I learned a lot in doing so.
Of course, I may be preaching to the choir here (in which case please tell
me to shut up and save my breath already;), but I thought you might be
interested.
Cheers,
has (floating contentedly amongst a sea of objects in a state of perfect
enlightenment and bliss;)
p.s. If all that's bored the bits off you, try the following for some light
refreshment:)
http://www.spiteyourface.com/one/film.html