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

This forum is meant for questions and discussions about the X# language and tools
Post Reply
FdeRaadt
Posts: 31
Joined: Wed Sep 01, 2021 12:49 pm

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

Post 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
User avatar
robert
Posts: 4279
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

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

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
FdeRaadt
Posts: 31
Joined: Wed Sep 01, 2021 12:49 pm

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

Post 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
User avatar
robert
Posts: 4279
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

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

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
g.bunzel@domonet.de
Posts: 97
Joined: Tue Mar 01, 2016 11:50 am
Location: Germany

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

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