Page 1 of 2
the use of 'out' in a parameter list / situation
Posted: Fri Mar 24, 2017 4:49 pm
by Phil Hepburn
Hi guys,
Can anyone please suggest some X# syntax to show how to use the 'out' option in a parameter list.
I had a quick fumble around but with no good results.
End of day, brain hurts, nee my Forum colleagues ;-0)
Apparently Tuples can happily replace the use of 'OUT'.
HELP !!!
TIA,
Phil.
the use of 'out' in a parameter list / situation
Posted: Fri Mar 24, 2017 5:01 pm
by lumberjack
Phil,
Is that not REF?
Code: Select all
METHOD SyMethod(in AS STRING, out REF STRING)
Johan
the use of 'out' in a parameter list / situation
Posted: Fri Mar 24, 2017 5:01 pm
by Phil Hepburn
Hi again,
Having had another end of day fumble, I think I have a start, you know, my foot in the door!
Here are a couple of small images :-
- Out_01.jpg (23.68 KiB) Viewed 600 times
- Out_02.jpg (30.3 KiB) Viewed 600 times
I got success once I stopped trying to include 'as'.
Have a nice weekend,
Phil.
the use of 'out' in a parameter list / situation
Posted: Fri Mar 24, 2017 5:04 pm
by Phil Hepburn
Hi Johan,
I am not sure, I thought the REF idea was out of fashion a while back. These sorts of things are no much in my experience.
However, I do like the Tuple (sexy way) I will need to experiment.
I will feed back here if I get anything useful.
Regards,
Phil.
the use of 'out' in a parameter list / situation
Posted: Sun Mar 26, 2017 12:15 pm
by robert
Johan,
See
https://www.xsharp.eu/help/parameters.html
Code: Select all
parameterList : LPAREN (parameter (COMMA parameter)*)? RPAREN
;
parameter : (attributes)? SELF? identifier (ASSIGN_OP expression)? (parameterDeclMods datatype)?
| ELLIPSIS
;
parameterDeclMods : (AS | REF | OUT | IS | PARAMS) CONST?
;
So AS, REF, OUT, IS and PARAMS are mutually exclusive.
Robert
the use of 'out' in a parameter list / situation
Posted: Sun Mar 26, 2017 3:30 pm
by lumberjack
Thanks Robert,
Sorry for any confusion, responded and then only checked the manual and did see OUT is recognized.
The same effect can be "simulated" with REF, provided you initialize the parameter before passing, which the OUT does not require. Both have its place.
REF: The parameter might be changed by the called method.
OUT: The parameter has to be set by the called method.
Regards,
Johan
the use of 'out' in a parameter list / situation
Posted: Mon Mar 27, 2017 10:19 am
by Phil Hepburn
An interesting short post Johan,
Thanks, I will now give these ideas a go in a test 'rig'.
Speak soon,
Phil.
the use of 'out' in a parameter list / situation
Posted: Mon Mar 27, 2017 11:10 am
by Frank Maraite
Hi Johan,
this
Johan Nel wrote:
REF: The parameter might be changed by the called method.
OUT: The parameter has to be set by the called method.
wasn't clear to me. Thanks!
Does this mean OUT parameters are always NULL at the beginning and should be tested !NULL before return?
Frank
the use of 'out' in a parameter list / situation
Posted: Mon Mar 27, 2017 11:27 am
by lumberjack
Hi Frank,
Frank Maraite wrote:
this wasn't clear to me. Thanks!
Does this mean OUT parameters are always NULL at the beginning and should be tested !NULL before return?
No, it will raise an error during compilation that the parameter is not set.
Code: Select all
FUNCTION TestOut(h AS STRING, w OUT STRING) AS STRING
RETURN h + " " + w
error XS0177: The out parameter 'w' must be assigned to before control leaves the current method
Regards Johan
the use of 'out' in a parameter list / situation
Posted: Mon Mar 27, 2017 4:26 pm
by Phil Hepburn
Hi guys - Johan, Frank, and any others interested,
Attached are a couple of small images to help show the functionality etc.
OUT must change in the method code, and REF can change but does not have to. That's how it seems to me.
I suggest you try these out carefully for yourself before you use them, any guy who is not familiar with their use. Just so you know what is going on - check below :-
- REfOut_01.jpg (26.59 KiB) Viewed 602 times
- REfOut_02.jpg (42.4 KiB) Viewed 602 times
- REfOut_03.jpg (36.63 KiB) Viewed 602 times
- RefOut_04.jpg (42.49 KiB) Viewed 602 times
- RefOut_05.jpg (40.91 KiB) Viewed 602 times
Hope this interests a few of you ;-0)
Cheers,
Phil.