by
johnmunro >> Tue, 21 Jan 2003 11:05:58 GMT
So, what does isOneOf actually do? And how did you find it? (We respect anonymity of sources...)
Basically, it returns true if the receiver is equal to any of the parameters.
To demonstrate what it does, let's look at an example. Let's say you had a method which returned a string, and if the return value was any of three values you want to do something. Normally you'd do something like this:
if getString = "one" or getString = "two" or getString = "three" then
...
endif;
The problem with this is that you are calling getString three times, and this could be a bad idea if that method is computationally expensive. If this was the case, you would probably cache the value in a variable:
vars
tmpString : String;begin
tmpString := getString;
if tmpString = "one" or tmpString = "two" or tmpString = "three" then ...
endif;
end;
There's nothing really wrong with this, but it does mean you have to create a variable, and in a large method you probably don't want to create too many of these temporary variables because it gets cluttered (and takes up memory, but it's up to you how pedantic you want to get about that).
So how would isOneOf help? Well, the code below has the exact same logical effect as the code fragments above, but without either of the drawbacks:
if getString.isOneOf("one", "two", "three") then
...
endif;
I'm afraid I'm going to have to disappoint you on the source front - no informats or spies involved - I just did a search of RootSchema for ParamListType (in an attempt to get some more information on how I might use it) and it came up with isOneOf. From the name of the method I thought it might be something like the method I was trying to create, and after some testing I decided that that's exactly what it was.
John Munro
---
Synergist Limited - Home of FileVision
The Bioscience Innovation Centre
Cowley Road, Cambridge, UK
CB4 0DS
Telephone: +44 (0) 1223 478200
Fax: +44 (0) 1223 477969
Email:
john.munro@filevision.com
Web:
http://www.filevision.com
The contents of this communication are confidential and are only intended to be read by the addressee. We apologize if you receive this communication in error and ask that you contact Synergist Limited immediately to arrange for its return. The use of any information contained in this communication by an unauthorized person is strictly prohibited. Synergist Limited cannot accept responsibility for the accuracy or completeness of this communication as it is being transmitted over a public network. If you suspect this message may have been intercepted or amended, please inform Synergist Limited.