Hi Alex,
1. That's a correct error. You are trying to cast ClassA to ClassB, in other words telling the compiler that ClassA contains everything ClassB has, but this is not true. It's easier to explain by including a member of the class:
Code: Select all
CLASS classA
EXPORT AvailaboleInBothAandB AS INT
CLASS classB INHERIT classA
EXPORT OnlyAvailableInB AS INT
// it also inherits "AvailaboleInBothAandB" from the parent class
FUNCTION Start( ) AS VOID
LOCAL a AS classA
LOCAL b AS classB
a:=classA{}
b:=(classB)a
? b:OnlyAvailableInB
It's very similar code to yours, and as you can see, the "a" var holds an instance of the classA type, which only contains the OnlyAvailableInB iVar. In the next line, we are trying to (cast and) assign this object to a var of type classB, which is supposed to have two iVars, the inherited one "AvailaboleInBothAandB", but also the one defined in that class, "OnlyAvailableInB". Clearly our object has only one of those iVars, hence the error.
What is possible to do, is to make the opposite cast:
Code: Select all
FUNCTION Start( ) AS VOID
LOCAL a AS classA
LOCAL b AS classB
b:=classB{}
a:=(classA)b
? a:AvailaboleInBothAandB
here "b" contains an instance of the child class classB, which includes everything the parent classA has, so it's fine to cast it into classA
2. Yes, unfortunately this is extremely difficult to emulate in .Net, but actually we are working right now trying to imporve this as much as possible. If you'd like, please post some exact samples of code, so we can give you some suggestions on how to make it adjust to make it work somewhat more similar to VO.
.