iOS Question Bug? Reading value of switch (checkbox)

mcorbeel

Active Member
Licensed User
Longtime User
I use this in my B4i code:

B4X:
If CheckBox_PrivateCar.Value Then
f.Value = "1"
Else
.Value = "0"
End If

This gives error:
Stack Trace: (
"0 Dylius SignalHandler + 112",
"1 libsystem_platform.dylib 0x21df606f _sigtramp + 34",
"2 Dylius -[b4i_class_edithours _readinput:] + 742",
"3 Dylius -[b4i_page_edithours _page_edithours_resize::] + 830",
"4 CoreFoundation <redacted> + 68",
"5 CoreFoundation <redacted> + 292",
"6 Dylius +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1790",
"7 Dylius -[B4IShell runMethod:] + 588",
"8 Dylius -[B4IShell raiseEventImpl:method:args::] + 1908",
"9 Dylius -[B4IShellBI raiseEvent:event:params:] + 1328"
)

However, if I change
B4X:
If CheckBox_PrivateCar.Value Then
into
B4X:
If CheckBox_PrivateCar.Value = True Then
then the error is gone.

Strange?
 

Sandman

Expert
Licensed User
Longtime User
Yes, that seems strange, I don't have any real insights there, sorry.

I have to ask, in line four you're missing an "f". That's not intentional, right?

Also, I would guess that you could swap the whole code to:
B4X:
f.Value = CheckBox_PrivateCar.Value
 
Upvote 0

mcorbeel

Active Member
Licensed User
Longtime User
I have seen it now in other places in my code and can confirm... Seems to be a difference between B4A en B4i.
In B4A you can just write:
B4X:
if boolean_value then
in B4i this sometimes gives error and you need to write:
B4X:
if boolean_value = True then
 
Upvote 0

mcorbeel

Active Member
Licensed User
Longtime User
Yes, that seems strange, I don't have any real insights there, sorry.

I have to ask, in line four you're missing an "f". That's not intentional, right?

Also, I would guess that you could swap the whole code to:
B4X:
f.Value = CheckBox_PrivateCar.Value
yes... the "f" got lost in the copy/past process ...
 
Upvote 0

mcorbeel

Active Member
Licensed User
Longtime User
I followed Sandman's suggestion and wrote
B4X:
f.Value = CheckBox_PrivateCar.Value
and the error was back...
then I changed it to
B4X:
if CheckBox_PrivateCar.Value = True then
    f.Value = "1"
end if
and the error is gone...

Also tried to create a project that shows the issue, but it does not crash...
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
I am enough lazy to write If boolean_value = True Then . Never noticed any problem with If boolean_value Then.

What is f in your sample ? f.Value is Boolean ? If so, why do you use f.Value = "1" ? (this gives an error Cannot parse: 1 as boolean)
 
Upvote 0

mcorbeel

Active Member
Licensed User
Longtime User
iOS doesn't have a real boolean type. It is actually a number that is either 0 or 1. I'm not sure, but it might be related to the issue you encounter.
Whatever I change... the error comes keeps coming back... starting to feel desparate.
Are you willing to check my app in private? I don't like sharing it publicly because it contains too much info. Also you need special QR-code to use app... etc.
 
Upvote 0

mcorbeel

Active Member
Licensed User
Longtime User
I am enough lazy to write If boolean_value = True Then . Never noticed any problem with If boolean_value Then.

What is f in your sample ? f.Value is Boolean ? If so, why do you use f.Value = "1" ? (this gives an error Cannot parse: 1 as boolean)
f.value is a string
 
Upvote 0

mcorbeel

Active Member
Licensed User
Longtime User
I succeeded in creating a demo app that shows the issue, but I cannot upload it because I get " The uploaded file is too large for the server to process. " So I placed it on my server.
URL in next post reply...
The app start with a splash screen, then it downloads and shows a list of items (expense notes). When you tap the button "New expense note" the error is raised.
As far as I can see the error comes from the "ReadInput" sub in "Class_ExpenseNote".
Thanks all for trying...
 
Last edited:
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
Looks as a bug.

Replace
B4X:
If modCommon.Expensenote_Record.IsInitialized = True Then
to
B4X:
Dim f As Boolean = modCommon.Expensenote_Record.IsInitialized
If f Then
If f = True also works.

Guess, a problem is in a combination of factors. I used If x.IsInitialized then , don't remember troubles.
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
I think that your second example cast the value to a boolean, which then makes the if work.

But that leaves the question why example 1 doesn't work. Because it seems reasonable that IsInitialized also is a boolean. Could it be something else, like 0 or 1? What happens if you change the first example so it compares to 1 instead of True?
 
Upvote 0

mcorbeel

Active Member
Licensed User
Longtime User
I followed Semen's advise and changed my code in the sample app to:
B4X:
Dim b As Boolean = modCommon.Expensenote_Record.IsInitialized
if B then
...
and the error was gone.

So I did the same changes im my real app... and believe it or not, the error was back!
Then I wrote:
B4X:
Dim b As Boolean = modCommon.Expensenote_Record.IsInitialized = True
if B then
...
and now it stays okay...
 
Upvote 0

mcorbeel

Active Member
Licensed User
Longtime User
I think that your second example cast the value to a boolean, which then makes the if work.

But that leaves the question why example 1 doesn't work. Because it seems reasonable that IsInitialized also is a boolean. Could it be something else, like 0 or 1? What happens if you change the first example so it compares to 1 instead of True?
Comparing the value to 1 i cannot do because the class is shared with a B4A project...
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
As I understand, IsInitialized returns id (something similar to B4i objects).

So I did the same changes im my real app... and believe it or not, the error was back!

I believe :) And something talks to me that a problem, probably, is not relative to boolean values and not relative to IsInitialized as it is.

I added Sleep into initial example and a program began to work also. So maybe there is a reason to look Sleep/Wait inside the program. Who knows, how B4i detects that an object is already initialized. For example, in Objective-C to allocate object and to initialize are different methods.
 
Upvote 0

mcorbeel

Active Member
Licensed User
Longtime User
Welll, after working on other parts of my app, the error came back on the old place, without having changed it. So I also put in "Sleep(0)" en that solved the issue. The mystery keeps on growing... but at least I can continue now...
 
Upvote 0
Top