the use of 'out' in a parameter list / situation

This forum is meant for anything you would like to share with other visitors
User avatar
lumberjack
Posts: 727
Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa

the use of 'out' in a parameter list / situation

Post by lumberjack »

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
______________________
Johan Nel
Boshof, South Africa
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

the use of 'out' in a parameter list / situation

Post by Phil Hepburn »

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 :-
RefOut_11.jpg
RefOut_11.jpg (29.93 KiB) Viewed 259 times
RefOut_12.jpg
RefOut_12.jpg (29.92 KiB) Viewed 259 times
RefOut_13.jpg
RefOut_13.jpg (24.87 KiB) Viewed 259 times
RefOut_14.jpg
RefOut_14.jpg (36.13 KiB) Viewed 259 times
RefOut_15.jpg
RefOut_15.jpg (30.98 KiB) Viewed 259 times
RefOut_16.jpg
RefOut_16.jpg (39.42 KiB) Viewed 259 times
RefOut_17.jpg
RefOut_17.jpg (50.21 KiB) Viewed 259 times
Hope this interests a few guys,
Cheers,
Phil.
User avatar
lumberjack
Posts: 727
Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa

the use of 'out' in a parameter list / situation

Post by lumberjack »

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
______________________
Johan Nel
Boshof, South Africa
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

the use of 'out' in a parameter list / situation

Post by Phil Hepburn »

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 :-
RefOut_21.jpg
RefOut_21.jpg (51.26 KiB) Viewed 259 times
RefOut_22.jpg
RefOut_22.jpg (53.37 KiB) Viewed 259 times
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 :-
RefOut_23.jpg
RefOut_23.jpg (23.17 KiB) Viewed 259 times
RefOut_24.jpg
RefOut_24.jpg (50.87 KiB) Viewed 259 times
RefOut_25.jpg
RefOut_25.jpg (51.73 KiB) Viewed 259 times
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.
User avatar
lumberjack
Posts: 727
Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa

the use of 'out' in a parameter list / situation

Post by lumberjack »

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:

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
You can try the following with a NULL string though and it will fail at runtime:

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
Post Reply