Day 047 - Variable return types, and getting stuck on object references

Yesterday I completed three unit tests for my test class's methods, but I had problems running two of those tests. I couldn't find any obvious reasons why the tests wouldn't run. So today I tried the last resort: I restarted the IDE.

I made a modification to the third method to check on how WinDev handles runtime determination of return types. Here's the method code:

PROCEDURE MethodC(nParam is int)
nValue is int
sValue is string
nValue = 12
sValue = "abc"
IF nParam = 1 THEN
	RESULT MethodB(nValue)
END
RESULT MethodB(sValue)

Depending on the value passed in, this method returns either an int or a string. It then calls MethodB (I was thrown off here because I started to write the code as self.MethodB, but the compiler complained), which has one syntax for any and all types and another syntax for int types:

PROCEDURE MethodB(value)
Debug("automatic syntax used for value " + value)
RESULT value

PROCEDURE MethodB(value is int)
Debug("int syntax used for value " + value)
RESULT value

The system log showed that the appropriate version was called. 

I'm not sure off the top of my head where I'd use code like this, but it's nice to know the capability is there. 

One thing I'm not certain about is when the assignment of types and/or the automatic conversion of types breaks down, and what kinds of errors I can expect. Presumably the runtime will barf if I attempt to assign a query to an int or something like that. 

Lots of rope here to hang yourself with, so go easy. 

Hitting the wall

I did want to show an example of how to assign object references, but I ran into significant problems trying to the equivalent of storing a reference to one object inside another object of the same type. I took this to the WinDev Skype chat without any clear result (at least as of the time I'm writing this). Hopefully I'll have something better to report on Monday.