Passing a field reference parameter
Martin Obongita
martin.obongita at yahoo.com
Thu Sep 26 14:42:46 UTC 2024
Hi Doug. Your answers are detailed, leaving no room for getting lost. Just what a student needs. CHEERS, my brother!
On Thursday, September 26, 2024 at 12:26:09 AM GMT+3, Doug Easterbrook <doug at artsman.com> wrote:
hi Martin.
There is one key difference: and that is whether ytou want use the method call as a function, or just call it and check the values after.
eg, to call a method in object called myObject
do myObject.$aMethod(Parameter)
thats all you can do.
and myObject (parameter) will change the value of the parameter, which as a field reference changes it in the place it is called from
to call a function and pass the result deeper to other functions. here’s a fairly arbitrary example
calculate myResult as left(low(trim(con(myObject.$aMethod(Parameter),’ ‘,someOtherValue)))
in that case, it would be helpful to use quit method return ’textValue’ in myObject.$aMethod
to give a more concrete example, suppose you have some method that formats a string as a phone number. In other words, it might change a text value like 4035551212 into (403) 555-1212 and strip out all alpha characters and extraneous spaces. Lets also suppose we have a method someplace that is called ‘$formatPhoneNumber'
personally, I would write the function as
$formatPhoneNumber(FieldParameter)# do stuff to format the phone number locally
# optionally, change the result in the field parameter — in your case I would do this since your standard is to use field parameters and expect the value to be chnaged.calculate FieldParameter as LocalFormattedPhoneNumber
quit method returns LocalFormattedPhoneNumber
now I can do one of two things
Calculate thePhoneNumber as ‘403551212'do $formatPhoneNumber(thePhoneNumber)
or, I can do
Calculate thePhoneNumber as ‘403551212'calculate displayPhone as con(‘Home: ‘,$formatPhoneNumber(thePhoneNumber))
in the second instance, the returns lets me use it as a function, which is very handy.
if you have a LOT or parameters, then I generally return true or false if the function worked or not.
if lets you do things in if, switch statements , while or for loops
eg. suppose we pass a phone nubmer, a country in which we want to format it (north america is different than europe or africa), and wether it can be empty or not
if $isThePhoneNumberValid(thePhoneNumber,country,’emptyAllowed') then # this is validelse # this is not validend if
this saves you doing things like checking if the phone number is valid and not empty kind of thing.
thats my two cents.
Doug EasterbrookArts Management Systems Ltd.mailto:doug at artsman.comhttp://www.artsman.comPhone (403) 650-1978
On Sep 25, 2024, at 1:33 PM, Martin Obongita via omnisdev-en <omnisdev-en at lists.omnis-dev.com> wrote:
Hi,
I'm a great fun of passing field reference parameters. It is an easy way of setting values, doing some calculations and getting the results back without the need of a return value.
But sometimes I keep asking myself, when is it necessary to pass a field reference and when should a return value on "quit method" be used instead?
I'd be happy to hear the proper way of working with field ref param.
Thanks.
_____________________________________________________________
Manage your list subscriptions at https://lists.omnis-dev.com
Start a new message -> mailto:omnisdev-en at lists.omnis-dev.com
More information about the omnisdev-en
mailing list