B4J Question Boolean in custom view class appears to reset on its own

TorontoJim

Member
Licensed User
Longtime User
I have a boolean value that is changing, apparently, in it's own. I know ... I've spent the last two hours trying to figure this out.

The boolean, located in the custom view module, is named "boolIgnoreDoubleClickToOpen"

This is my custom view module where it is initialized and set:

B4X:
Sub Class_Globals
    Private fx As JFX
    Private EventName As String
    Private CallBack As Object
    Private mBase As Pane
    Private ExplorerWindow As ListView
    Private anchorEW As AnchorPane
    Private ExplorerDropDown As ComboBox
    Private frm As Form
    Private dialogue8 As Dialogs8
    Private boolIgnoreDoubleClickToOpen As Boolean
    Private boolDropbox As Boolean
    Private c As ContextMenu
    Private JO As JavaObject
    Private strCurrentDirectoryURI As String
    Private listThisDirectoryDirs As List
    Private listThisDirectoryFiles As List
    Private listThisDirectoryContents As List
    Private DefaultImage As Image
    Private mapContextMenus As Map
    Private mapClick As Map
    Private lvFileExplorer As ListView
End Sub

Public Sub Initialize (vCallback As Object, vEventName As String)
    EventName = vEventName
    CallBack = vCallback
    ExplorerDropDown.Initialize("ExplorerDropDown")
    ExplorerWindow.Initialize("ExplorerWindow")
    JO.InitializeNewInstance("javafx.beans.property.SimpleObjectProperty",Array(Me))
    If File.IsDirectory("C:\Users\User", "Dropbox") = True Then
        boolDropbox = True
    End If
    Log("boolDropbox1: " & boolDropbox)
    boolIgnoreDoubleClickToOpen = False  <-- Here is where I initially set it.
    dialogue8.Initialize
    mapClick.initialize
    mapClick.Put("LastSelectedIndex", -1)
    listThisDirectoryDirs.Initialize
    listThisDirectoryFiles.Initialize
    listThisDirectoryContents.Initialize
    Log("bool3: " & boolIgnoreDoubleClickToOpen)
End Sub

Public Sub IgnoreDoubleClickOpen(boolIgnore As Boolean)
    boolIgnoreDoubleClickToOpen = boolIgnore
    Log("bool1: " & boolIgnoreDoubleClickToOpen)
End Sub

Now this is the Main module, where I attempt to modify it:


B4X:
Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.SetFormStyle("UNIFIED")
    MainForm.RootPane.LoadLayout("mainform") 'Load the layout file.
    MainForm.Icon = fx.LoadImage(File.DirAssets, "folder_magnify.png")
    MainForm.Show
    explorer.Initialize(Me, "file_explorer")
    intSelectedIndex = -1
    mapSelectedURI.Initialize
    dialogue8.Initialize
    explorer.IgnoreDoubleClickToOpen(True)  <---------------------- Changing it here
    'CallSubDelayed2(explorer, "IgnoreDoubleClickOpen", True)  <--- I've tried it both ways
End Sub

From the log statements, it gets set to True when I call the public class method. However, the next time I test it, it has reverted back to False. The method IgnoreDoubleClickOpen is the only place that it gets set. I've done a Quick Search and also checked line by line, more than once for both.

I've also tested this through Debug Mode and Release Mode (through the IDE & launching the jar on its own).

What would cause the boolean to NOT hold the assigned value, once it passes out of the method that sets it?
 

somed3v3loper

Well-Known Member
Licensed User
Longtime User
What is the next time you tested it ?
If you restart the application it would initialize your class again setting variables to their default values (
boolIgnoreDoubleClickToOpen=False)

I hope I understood you problem well and sorry if my post is not relevant :)
 
Upvote 0

TorontoJim

Member
Licensed User
Longtime User
I have log statements throughout, wherever I'm testing the value. That's what I mean by testing it. The code above only shows a couple of them.
 
Upvote 0

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
I remember having a problem very similar to yours.

It happens that UI code sometimes run AFTER the rest of the code is ran. For example.

If you have
B4X:
sub test
checkbox.checked = true
Log(checkbox.checked) 'First log
callsubdelayed(me,"test2")
end sub

sub test2
Log(checkbox.checked) 'Second log

end sub


sub CheckBox_CheckedChange(check as boolean)
if check then
checkbox.checked = false
end if
End sub

The first Log will show True, but the next one will show False.
It is a bit confusing, but that is the general rule, some code will run after UI finish its queue.
 
Upvote 0

TorontoJim

Member
Licensed User
Longtime User
Yes, that was why I tried the CallSubDelayed2. It didn't have the effect, though.

I have another option, I'd just prefer to make it configurable without them having to edit the class file, but it's no big if they do. I just hate it when I can't bend a computer to my will **insert maniacal laughter**
 
Upvote 0

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
jeje...

Javafx is just to stubborn, the CallsubDelayed sometimes goes first in the queue and sometimes last.

The way i solved was to put a Control parameter for the sub, something like this:


B4X:
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.SetFormStyle("UNIFIED")
'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
MainForm.Show



Dim checkbox As CheckBox
checkbox.Initialize("checkbox")
checkbox.Tag = "AvoidBeingChanged"
checkbox.Checked = True



End Sub

Sub checkbox_CheckedChange(Checked As Boolean)
Dim checkbox As CheckBox = Sender

If Not(checkbox.Tag = "AvoidBeingChanged") Then
checkbox.Tag = "Changable"
Else
'Do something here, the first time will not run, it will only change the "availability" of the node.
End If

End Sub
 
Upvote 0

TorontoJim

Member
Licensed User
Longtime User
It would kind of ruin the idea of the interface. Unless Erel or someone comes up with some magic, I'll just drop that one small part of it. It still confuses me that it isn't doing what it "should" be doing when you look at it in a linear way.
 
Upvote 0
Top