Hi Phil,
Think you have summed it up quite nicely.
Maybe look at a string example, where the sRef have to be initialized before the call. Remember numbers default to Zero.
Johan
the use of 'out' in a parameter list / situation
- lumberjack
- Posts: 727
- Joined: Fri Sep 25, 2015 3:11 pm
- Location: South Africa
the use of 'out' in a parameter list / situation
______________________
Johan Nel
Boshof, South Africa
Johan Nel
Boshof, South Africa
- Phil Hepburn
- Posts: 743
- Joined: Sun Sep 11, 2016 2:16 pm
the use of 'out' in a parameter list / situation
Hi Johan,
I actually tried the strings first, but thought I had too many images to post. I also thought that int and string would be different since we can have a nullable ints but that strings don't - and a default would be an empty string.
Please feel free to add your knowledgeable details to these captured images :-
Hope this interests a few guys,
Cheers,
Phil.
I actually tried the strings first, but thought I had too many images to post. I also thought that int and string would be different since we can have a nullable ints but that strings don't - and a default would be an empty string.
Please feel free to add your knowledgeable details to these captured images :-
Hope this interests a few guys,
Cheers,
Phil.
- lumberjack
- Posts: 727
- Joined: Fri Sep 25, 2015 3:11 pm
- Location: South Africa
the use of 'out' in a parameter list / situation
Hi Phil,
Think you can maybe just show the warning message when cRef is not initialized in the calling block before passed into the calling method/func/proc.
Johan
Think you can maybe just show the warning message when cRef is not initialized in the calling block before passed into the calling method/func/proc.
Johan
______________________
Johan Nel
Boshof, South Africa
Johan Nel
Boshof, South Africa
- Phil Hepburn
- Posts: 743
- Joined: Sun Sep 11, 2016 2:16 pm
the use of 'out' in a parameter list / situation
Hi Johan,
An earlier message of yours suggested that I needed to do more than I seemed able at this end.
Is it that the X# version works differently to what you are referring to ? As regards Ref and Out variable inputs.
It seems possible for me to pass in Ref and Out, both of which have not been assigned a value, just declared as a value type. I get no errors for this - see below :-
When I tried it with INTs the results were as if the default of zero was applied.
What exactly do you wish me to do ?
Here are the inputs and results for DateTimes - it would appear that unassigned inputs to Ref and Out are given a default DateTime of 0001, 01, 01 00:00:00.
Check these small images :-
So as far as I can tell the compiler supplies default values if values don't exist.
Is this what you needed to know?
This behaviour could be a real "catch you out" (or 'gotcha' as Willie says) I feel - what do you think ?
Best regards,
Phil.
An earlier message of yours suggested that I needed to do more than I seemed able at this end.
Is it that the X# version works differently to what you are referring to ? As regards Ref and Out variable inputs.
It seems possible for me to pass in Ref and Out, both of which have not been assigned a value, just declared as a value type. I get no errors for this - see below :-
When I tried it with INTs the results were as if the default of zero was applied.
What exactly do you wish me to do ?
Here are the inputs and results for DateTimes - it would appear that unassigned inputs to Ref and Out are given a default DateTime of 0001, 01, 01 00:00:00.
Check these small images :-
So as far as I can tell the compiler supplies default values if values don't exist.
Is this what you needed to know?
This behaviour could be a real "catch you out" (or 'gotcha' as Willie says) I feel - what do you think ?
Best regards,
Phil.
- lumberjack
- Posts: 727
- Joined: Fri Sep 25, 2015 3:11 pm
- Location: South Africa
the use of 'out' in a parameter list / situation
Hi Phil,
Sorry just tested now and seems the compiler by default set string to "" even if not specified /v02.
What I tried to highlight is that it might be dangerous if not initialized:
You can try the following with a NULL string though and it will fail at runtime:
Sorry just tested now and seems the compiler by default set string to "" even if not specified /v02.
What I tried to highlight is that it might be dangerous if not initialized:
Code: Select all
FUNCTION Start() AS VOID
LOCAL o AS MyClass
RefClassTest(o)
?o:RefValue
RETURN
FUNCTION RefClassTest(o REF MyClass) AS VOID
o:RefValue := "Foo"
RETURN
CLASS MyClass
EXPORTED RefValue AS STRING
CONSTRUCTOR(v AS STRING)
SELF:RefValue := v
RETURN
END CLASS
Code: Select all
FUNCTION Start() AS VOID
LOCAL s AS STRING
TestRef(s)
?s
RETURN
FUNCTION TestRef(s REF STRING) AS VOID
IF s:Length > 0
s := "String length > 0"
ELSE
s := "String length = 0"
ENDIF
RETURN
______________________
Johan Nel
Boshof, South Africa
Johan Nel
Boshof, South Africa