casting
Differences
This shows you the differences between two versions of the page.
Last revisionBoth sides next revision | |||
casting [2018/09/03 19:03] – created wolfgangriedmann | casting [2018/09/04 03:35] – wolfgangriedmann | ||
---|---|---|---|
Line 16: | Line 16: | ||
The first assignment will compile and work in X#, because the compiler knows the type of both variables and inserts a conversion method - so this code is safe. | The first assignment will compile and work in X#, because the compiler knows the type of both variables and inserts a conversion method - so this code is safe. | ||
The second assignment will not compile in X# because it cannot work in a .NET world - it is simply not admitted. A member of the development team stated: '' | The second assignment will not compile in X# because it cannot work in a .NET world - it is simply not admitted. A member of the development team stated: '' | ||
+ | |||
+ | In VO, sometimes casts are used as follows: | ||
+ | <code visualfoxpro> | ||
+ | local oWindow as DataWindow | ||
+ | ... | ||
+ | p := @oWindow</ | ||
+ | and then p is is assigned to an int | ||
+ | <code visualfoxpro> | ||
+ | n := p</ | ||
+ | The variable n is then used in several ways, like sorts, callbacks, in parameters, etc. To access the object again, n is casted to the object: | ||
+ | <code visualfoxpro> | ||
+ | This works in VO, until the object has not moved by the garbage collector. When the garbage collector has moved the object, the pointer and the int variable still point to a (maybe valid) memory location, but not to the original object. Therefore this is very dangerous also in VO. | ||
+ | In .NET such pointers are not allowed, therefore the development team has disallowed the compilation of such code. | ||
+ | The only valid representation of an object by a numeric variable is when the numeric is an index to an array of objects, and it remains valid also when the garbage collector kicks in. But this type of valid code is rarely seen in VO code. | ||
Please see the entire thread about it in the X# forum: [[https:// | Please see the entire thread about it in the X# forum: [[https:// | ||
casting.txt · Last modified: 2018/09/07 04:04 by wolfgangriedmann