Re: Checking a Record for a Field
Re: Checking a Record for a Field
- Subject: Re: Checking a Record for a Field
- From: Axel Luttgens <email@hidden>
- Date: Mon, 16 Nov 2015 18:50:55 +0100
> Le 16 nov. 2015 à 15:17, S. J. Cunningham a écrit :
>
> I have a handler to which I would like to pass a variable number of arguments. I am using a record to pass the arguments and then checking in the handler whether or not a specific field exists so I can skip it if it doesn't. Here is how I am doing the check:
>
> on myCoolHandler(someRecord)
> […]
> end myCoolHandler
>
> on checkForField_3(theRecord)
> […]
> end checkForField_3
>
> set theRecord to {Field_1:"Field 1", Field_2:"Field 2"}
> myCoolHandler(theRecord)"
>
> Is there an easier way to accomplish this? In particular, is there a way to parameterize the check? As it is, I need a separate "check handler" for each field I want to check.
Hello Steve,
You already got some proposals.
Perhaps may you pick an "impossible" value for each of your arguments, in which case you could rely on the behavior of the & operator when applied to records.
For example, assuming none of your arguments may take missing value as a value:
on myCoolHandler(someRecord)
set someRecord to someRecord & {Field_1:missing value, Field_2:missing value, Field_3:missing value}
if Field_1 of someRecord is not missing value then
— do something with Field_1
end if
if Field_2 of someRecord is not missing value then
— do something with Field_2
end if
if Field_3 of someRecord is not missing value then
— do something with Field_3
end if
end myCoolHandler
set R to {Field_1:"a", Field_3:"c"}
myCoolHandler(R)
Not "parameterized", but remains quite legible.
HTH,
Axel
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden