xsharp.eu • Unable to cast object 'bBrowser.bDataColumn' to type 'bBrowser.bVirtualColumn'
Page 1 of 1

Unable to cast object 'bBrowser.bDataColumn' to type 'bBrowser.bVirtualColumn'

Posted: Fri Feb 18, 2022 5:01 pm
by FdeRaadt
Hello Everyone,

I've ran into some issues that seem unclear to me.

Error: Unable to cast object of type 'bTools.bBrowser.bDataColumn' to type 'bTools.bBrowser.bVirtualColumn'.

Regarding the following code in Xsharp:

Code: Select all

local oColumn		as bVirtualColumn
local oKolom		as bDatacolumn

oColumn := oBrowser:GetColumn(#AdresInfo)
oColumn:DataView := bViewStyle{,,BALIGN_CENTER,oFont}
oColumn:CaptionView := bViewStyle{,,BALIGN_CENTER,oFont}
oColumn:background := KleurB(WINDOWGRIJS,2)
What I find fascinating is that this (Runtime)Error is only visuable when my application crashes. Why does this code compile but leads to a RunTimeError. Shouldn't the compiler recognize this problem and warn me about this?

My second issue is that this code works in VO but in Xsharp it leads to crashing the application.

Any help or guidance is greatly appreciated

Frank

Unable to cast object 'bBrowser.bDataColumn' to type 'bBrowser.bVirtualColumn'

Posted: Fri Feb 18, 2022 5:13 pm
by robert
Frank,
It looks like your #AdresInfo column is not a bVirtualColumn but a normal bDataColumn.
oBrowser:GetColumn() is declared to return an object, so the compiler "assumes" you know what you are doing and that the column that you are trying to fetch is indeed a bVirtualColumn.
The compiler can't know that this is not the case.

Robert

Unable to cast object 'bBrowser.bDataColumn' to type 'bBrowser.bVirtualColumn'

Posted: Mon Feb 28, 2022 1:22 pm
by FdeRaadt
Hi Robert,

I've looked into the code and it turns out you're right. By changing oColumn to cDataColumn my problem is fixed.
I don't really like that the compiler doesn't warn me about these mistakes in my code. I have to manually test if changes to my code result in a RunTimeError but I've seen that topic was already discussed with Dick in another post.

Frank

Unable to cast object 'bBrowser.bDataColumn' to type 'bBrowser.bVirtualColumn'

Posted: Mon Feb 28, 2022 3:20 pm
by robert
Frank,
There is not much that the compiler can do in this case.
The GetColumn() method has been declared "AS OBJECT" , so the compiler has no way it can know what the real return value will be.

Robert

Unable to cast object 'bBrowser.bDataColumn' to type 'bBrowser.bVirtualColumn'

Posted: Tue Mar 01, 2022 9:58 am
by g.bunzel@domonet.de
Frank,

with GetColumn() you get back that column as it is created.
Create and add that Column as a VirtualColumn to the bBrowser and you get back a VirtualColumn.
No need for a casting.

Gerhard Bunzel