Getting the status of a WPF checkbox in X#

This forum is meant for questions and discussions about the X# language and tools
Post Reply
ic2
Posts: 1813
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

Getting the status of a WPF checkbox in X#

Post by ic2 »

I've already solved the issue which I will describe here but I just wonder why I have to do it as it is done now.

I am working on my Excel reader and changed from .Net Core to Vulcan dialect so I can create a DBF from the Excel sheet. On the WPF form I added a checkbox with name cbisheader and if checked the program knows that the first row in the Excel contains the headers.

So I used:

If cbisheader:Checked

This is the VO/Vulcan way but it doesn't work. I get:

Error XS0079 The event 'System.Windows.Controls.Primitives.ToggleButton.Checked' can only appear on the left hand side of += or -=

After some search (somebody wrote "Checked here is an event, not a bool, that happens when it is checked. You need a different property - presumably IsChecked.") I changed it to:

If cbisheader:isChecked

and got:

Error XS0266 Cannot implicitly convert type 'logic?' to 'logic'. An explicit conversion exists (are you missing a cast?)

Below what finally worked. But it doesn't make sense to me. I would expect the above should work, or this one but with a double =.

If cbisheader:isChecked=True

What is the logic behind this "logic"?

Dick
User avatar
Chris
Posts: 4599
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Getting the status of a WPF checkbox in X#

Post by Chris »

Hi Dick,

This is because apparently IsChecked is not of normal LOGIC type, but it returns a special type, a nullable logic. This is different in the sense it provides 3 states, yes, no and "don't know" (when the value is NULL).

In order to use such a type, you'd normally need to check first:

IF cbisheader:IsChecked:HasValue // returns false if it is NULL

and only if the above returns TRUE, then you can be sure that the var does hold a LOGIC value (and not NULL), and you can access this value with

IF cbisheader:IsChecked:Value // true or false

or with the (cast) that you used before.

The reason behind introducing Nullable types, is to provide this "do not know" value to common types, likes ints. So, for example, a nullable int can have all the values a normal int has, but it can also hold NULL, which may mean that the value has not be assigned yet, when reading it from a database the contents where corrupted, things like that. With a normal int, we would need to use for example by convention a value of -1 to denote "invalid vale", but this causes all sorts of problems, thus the introduction of nullable types in .Net.

Now, why on earth should a CheckBox have a "don't know" value in addition to checked and unchecked, I have no idea, you'd need to ask the people who designed WPF about this :)
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
ic2
Posts: 1813
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

Getting the status of a WPF checkbox in X#

Post by ic2 »

Hello Chris,

Thanks for the lesson. I can imagine the "don't know" - it is not uncommon, given the privacy rules, to see questions like Male/Female expanded with "don't want to say". So the nullable logic is the logic? I understand.

Dick

Dick
User avatar
lumberjack
Posts: 723
Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa

Getting the status of a WPF checkbox in X#

Post by lumberjack »

Hi Dick,
ic2 wrote:I've already solved the issue which I will describe here but I just wonder why I have to do it as it is done now.
Well I solved this long time ago, remember you can have a CheckBox with no initial value set. .NET don't allow NULL booleans or DateTime values.

I wrote this little #command to solve the problem based on the c# "?" to define Nullables:

Code: Select all

#command LOCAL <v0,...> AS <typ>? => ;
                   LOCAL <v0> AS System.Nullable< <typ> >

FUNCTION Start() AS VOID
    LOCAL lNull, lTrue, lFalse AS LOGIC?
    lTrue := TRUE
    lFalse := FALSE
    ?"Has value : ", lNull:HasValue, lTrue:HasValue, lFalse:HasValue
    ?"   Values : ", lNull:, lTrue, lFalse, e"Note only lTrue and lFalse displayed, lNull has no value, hence empty """
    ?"  Is null : ", lNull == NULL, lTrue == NULL, lFalse == NULL
    ?" Is false : ", lNull == FALSE, lTrue == FALSE, lFalse == FALSE
    ?"  Is true : ", lNull == TRUE, lTrue == TRUE, lFalse == TRUE
RETURN
Hope this helps...
______________________
Johan Nel
Boshof, South Africa
User avatar
wriedmann
Posts: 3668
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Getting the status of a WPF checkbox in X#

Post by wriedmann »

Hi Dick,

this reflects the SQL logic: a logic field in a SQL table can be true, false or null.

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
FFF
Posts: 1535
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

Getting the status of a WPF checkbox in X#

Post by FFF »

Yeah - and if the unknown moron who coined the "null" instead of "unknown", or better, "not assigned", had known better, many, many misconceptions could have been avoided...
Regards
Karl
(on Win8.1/64, Xide32 2.19, X#2.19.0.2.)
ic2
Posts: 1813
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

Getting the status of a WPF checkbox in X#

Post by ic2 »

Hello Karl,
Yeah - and if the unknown moron who coined the "null" instead of "unknown", or better, "not assigned", had known better, many, many misconceptions could have been avoided...
Probably the same guy who thought it was a good idea to make indexes zero based :evil: .

Dick
User avatar
lumberjack
Posts: 723
Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa

Getting the status of a WPF checkbox in X#

Post by lumberjack »

Haha,
ic2 wrote:
Yeah - and if the unknown moron who coined the "null" instead of "unknown", or better, "not assigned", had known better, many, many misconceptions could have been avoided...
Probably the same guy who thought it was a good idea to make indexes zero based :evil: .
Well a decimal system means 10 digits, not 11 like the way the average person think...
0...9 = 10 Numbers,
1...10 = 10 Numbers // Ask anybody with this mindset and they will tell you, oh yes 0 is also a number. Therefore 1...10 means actually 0...10 = 11 Numbers, it is actually the only Number system that uses this concept, 0...1 = 2 Numbers, 0...7 = 8 Numbers, 0..15 = 16 Numbers, 0...127 = 128 Numbers, 0..255 = 256 Numbers...

Even, how many fingers can you possibly see, is not 10 answers, it is 11... We not using a Decimal system actually, we on a Number[sub]11[/sub] system... No sorry it is actually Number[sub]21[/sub]... if showing fingers palm forward or backward is added, or if palm forward means "+", we have -10...9, again 21 possibilities...

I rest my case with /az as X# switch...
______________________
Johan Nel
Boshof, South Africa
Post Reply