This forum is meant for questions and discussions about the X# language and tools
wriedmann
Posts: 3755 Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy
Post
by wriedmann » Sat Jan 12, 2019 8:32 am
Hi,
the following fragment of code does not compiles anymore in Beta 8:
Code: Select all
tvItem.state := INDEXTOSTATEIMAGEMASK( ( word ( _cast , fCheck ) ) + 1 )
The entire function is the following:
Code: Select all
function TreeView_SetCheckState( hwndTreeView as ptr, hItem as ptr, fCheck as logic ) as logic pascal
local tvItem is _winTV_ITEM
local lSet as logic
if _and ( GetWindowLong( hwndTreeView , GWL_STYLE ), TVS_CHECKBOXES ) == TVS_CHECKBOXES
tvItem.mask := _or ( TVIF_HANDLE , TVIF_STATE )
tvItem.hItem := hItem
tvItem.stateMask := TVIS_STATEIMAGEMASK
tvItem.state := INDEXTOSTATEIMAGEMASK( ( word ( _cast , fCheck ) ) + 1 )
lSet := TreeView_SetItem( hwndTreeView, @tvItem )
else
lSet := false
endif
return lSet
I have changed that to
Code: Select all
if fCheck
tvItem.state := INDEXTOSTATEIMAGEMASK( word( 2 ) )
else
tvItem.state := INDEXTOSTATEIMAGEMASK( word ( 1 ) )
endif
Of course I have applied this change also to the VO version of my code.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
robert
Posts: 4520 Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands
Post
by robert » Sat Jan 12, 2019 11:06 am
Wolfgang,
This is exactly one of the cases where the cast is dangerous.
The word is 2 bytes, but what is the size of the logical fCheck ?
In VO the logic is represented as 32 bits, but who knows what the value is. Is a logic represented with all bits set to 1 or only one bit set to one? That makes a huge difference. If all bits are set to 1 then the word(_CAST, fCheck) will return 2^15. Otherwise it will return 1 (because intel is littel endian and the one is stored in the lower 2 bytes).
In .Net the logic is 8 bits. Casting 8 bits to a 16 bit value, what do you expect.
Your solution seems right to me.
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
Karl-Heinz
Posts: 774 Joined: Wed May 17, 2017 8:50 am
Location: Germany
Post
by Karl-Heinz » Sat Jan 12, 2019 11:07 am
Hi Wolfgang,
This seems to work:
Code: Select all
LOCAL fCheck AS LOGIC
LOCAL w AS WORD
fCheck := TRUE
// INDEXTOSTATEIMAGEMASK( ( word ( _cast , fCheck ) ) + 1 )
INDEXTOSTATEIMAGEMASK( (WORD) System.Convert.changeType ( fCheck , typeof(WORD) ) + 1 )
// -------
w := (WORD) System.Convert.changeType ( fCheck , typeof(WORD) ) + 1
IF fCheck
? "True" , w
ELSE
?"False" , w
ENDIF
But let's wait, until Robert jumps in .
regards
Karl-Heinz
robert
Posts: 4520 Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands
Post
by robert » Sat Jan 12, 2019 11:19 am
Karl-Heinz Rauscher wrote:
But let's wait, until Robert jumps in .
I clicked [Submit] a few seconds before you
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu