B4J Question [SOLVED] Form controls became disabled while running the app

Mark Stuart

Well-Known Member
Licensed User
Longtime User
Hi all,

I'm back into B4J now.

I built a form for editing a database record. This record is selected from a TableView row.
The edit form is shown and all controls are set from the reading of the database record.

I did have the edit form working where all controls (TextField, Combobox, and Label) were editable.
Now they are not.
I don't know what I may have set or changed that caused this to happen.

The property for all controls: Enabled and Visible are checked.
I have some buttons at the top of the form and they are not disabled and work when clicked.

Anybody have an idea what maybe happening?

Mark Stuart
 

Swissmade

Well-Known Member
Licensed User
Longtime User
Hi all,

I'm back into B4J now.

I built a form for editing a database record. This record is selected from a TableView row.
The edit form is shown and all controls are set from the reading of the database record.

I did have the edit form working where all controls (TextField, Combobox, and Label) were editable.
Now they are not.
I don't know what I may have set or changed that caused this to happen.

The property for all controls: Enabled and Visible are checked.
I have some buttons at the top of the form and they are not disabled and work when clicked.

Anybody have an idea what maybe happening?

Mark Stuart
Anybody have an idea what maybe happening?

Not without some code.
 
Upvote 0

Mark Stuart

Well-Known Member
Licensed User
Longtime User
There are 2 forms: one with the TableView and the other is the edit form.

Here is the function that gets the info from the TableView:
B4X:
Private Sub tvLicenses_MouseClicked (EventData As MouseEvent)
    If EventData.ClickCount = 2 Then
        Dim tv As TableView = Sender
        Dim row() As Object = tv.SelectedRowValues
        If row <> Null Then
            UserID = row(1)
            License_Edit.LicenseID = row(0)
            License_Edit.UserID = row(1)
            License_Edit.ProductID = row(2)
            License_Edit.CustomerID = row(3)
            License_Edit.Fullname = row(4)
            License_Edit.ProductName = row(5)
            License_Edit.Show
        End If
    End If
End Sub

And here's the complete code from the edit form:
B4X:
'Static code module
Sub Process_Globals
    Private fx As JFX
    Private frm As Form
    
    Public LicenseID As Int
    Public UserID As Int
    Public Fullname As String
    Public CustomerID As Int
    Public ProductID As Int
    Public ProductName As String
    
    Private Firstname As String
    Private LastName As String
    Private CompanyName As String
    
    'User Information
    'Private cbxUser As ComboBox
    Private lblUserName As Label
    Private lblUserEmail As Label
    Private lblCompanyName As Label
    
    'License Information
    Private lblLicenseID As Label
    Private txtLicenseKey As TextField
    Private cbxProduct As ComboBox
    Private txtProductDescription As TextArea
    Private lblProductVersion As Label
    Private cbxStatus As ComboBox
    Private txtToken As TextField
    Private txtIssuedDate As TextField
    Private txtActivatedDate As TextField
    Private txtInactivatedDate As TextField
    Private txtHTMLFilename As TextField
    Private lblEmailSentDate As Label
End Sub

Public Sub Show
    If frm.IsInitialized = False Then
        frm.Initialize("frm", 900,845)
        frm.RootPane.LoadLayout("License_Edit")
    End If
    
    frm.SetWindowSizeLimits(900,845,1200,1000)
    frm.WindowLeft = (fx.PrimaryScreen.MaxX - frm.Width) / 2
    frm.WindowTop = (fx.PrimaryScreen.MaxY - frm.Height) / 2
    
    ClearForm
    LoadcbxProduct
    LoadcbxStatus
    SetTextColor
    
    If LicenseID <> 0 Then
        frm.Title = "Edit User License"
        LoadLicenseRecord
    Else
        frm.Title = "New User License"
        Get_User_Info
    End If
    frm.ShowAndWait
End Sub

#Region LOAD DATA
Sub ClearForm
    'User Info
    lblUserEmail.Text = ""
    lblCompanyName.Text = ""
    
    'License Info
    lblLicenseID.Text = "0"
    cbxProduct.SelectedIndex = -1
    txtLicenseKey.Text = ""
    cbxStatus.SelectedIndex = 0
    txtToken.Text = ""
    txtIssuedDate.Text = ""
    txtActivatedDate.Text = ""
    txtInactivatedDate.Text = ""
    txtHTMLFilename.Text = ""
    lblEmailSentDate.Text = ""
End Sub

Sub LoadcbxProduct
    cbxProduct.Items.Clear
    Dim data As List = DBProducts.Products_GetProductNames
    cbxProduct.Items.AddAll(data)
End Sub

Sub LoadcbxStatus
    cbxStatus.Items.Clear
    cbxStatus.Items.AddAll(Array As String("Issued","Activated","Inactivated"))
End Sub

Sub SetTextColor
    Utils.Set_TextField_TextColor(txtLicenseKey)
    Utils.Set_TextField_TextColor(txtToken)
    Utils.Set_TextField_TextColor(txtIssuedDate)
    Utils.Set_TextField_TextColor(txtActivatedDate)
    Utils.Set_TextField_TextColor(txtInactivatedDate)
    Utils.Set_TextField_TextColor(txtHTMLFilename)
    Utils.Set_TextArea_TextColor(txtProductDescription)
End Sub

Sub LoadLicenseRecord
    Dim l As LicenseView = DBLicenses.License_GetByLicenseID(LicenseID)
    
    If Not(l.IsInitialized) Then
        fx.Msgbox(frm,"Record not Found!","Warning")
        Return
    End If
    
    lblUserName.Text = l.Fullname
    cbxProduct.SelectedIndex = cbxProduct.Items.IndexOf(l.ProductName)
    cbxStatus.SelectedIndex = cbxStatus.Items.IndexOf(l.Status)
    
    'User Information
    Firstname = l.Firstname
    LastName = l.Lastname
    lblUserEmail.Text = l.UserEmail
    lblCompanyName.Text = l.CompanyName
    CompanyName = l.CompanyName
    
    'License Information
    lblLicenseID.Text = LicenseID
    txtProductDescription.Text = l.ProductDescription
    lblProductVersion.Text = l.ProductVersion
    txtLicenseKey.Text = l.LicenseKey
    txtToken.Text = l.Token
    txtIssuedDate.Text = l.IssuedDate
    txtActivatedDate.Text = l.ActivatedDate
    txtInactivatedDate.Text = l.InactivatedDate
    txtHTMLFilename.Text = l.HTMLFilename
    lblEmailSentDate.Text = l.EmailSentDate
End Sub

Sub Get_User_Info
    Dim u As UserView = DBUsers.User_GetByUserID(UserID)
    lblUserName.Text = u.Firstname.Trim & " " & u.Lastname
    lblUserEmail.Text = u.UserEmail
    lblCompanyName.Text = u.CompanyName
    cbxStatus.SelectedIndex = 0
End Sub

Private Sub cbxProduct_SelectedIndexChanged(Index As Int, Value As Object)
    ProductName = Value
    ProductID = DBProducts.Products_GetProductIDByName(ProductName)
    txtProductDescription.Text = DBProducts.Product_GetDescription(ProductID)
End Sub

'Private Sub cbxUser_SelectedIndexChanged(Index As Int, Value As Object)
'   
'End Sub

'Sub LoadcbxUsers
'    cbxUser.Items.Clear
'    Dim data As List = DBUsers.Users_GetUserNames(CustomerID)
'    data.RemoveAt(0)
'    cbxUser.Items.AddAll(data)
'    cbxUser.SelectedIndex = cbxUser.Items.IndexOf(Fullname)
'End Sub
#End Region

#Region BUTTONS
Private Sub btnSave_Click   
    Dim l As License
    l.Initialize
    l.LicenseID = LicenseID
    l.UserID = UserID
    l.ProductID = ProductID
    l.LicenseKey = txtLicenseKey.Text
    l.Status = cbxStatus.Value
    l.IssuedDate = txtIssuedDate.Text
    l.ActivatedDate = txtActivatedDate.Text
    l.InactivatedDate = txtInactivatedDate.Text
    l.Token = txtToken.Text
    l.HTMLFilename = txtHTMLFilename.Text
    l.EmailSentDate = lblEmailSentDate.Text
    
    'save data
    DBLicenses.License_Save(l)
    CallSubDelayed(Licenses,"LoadLicenses")
    
    fx.Msgbox(frm,"License saved. Now create the HTML file","Attention")
End Sub

Private Sub btnGenerateLicenseKey_Click
    Dim lk As String = LicenseUtils.Generate_LicenseKey
    If lk = "" Then
        fx.Msgbox(frm,"License Key was unable to be generated!","Warning")
        Return
    End If
    txtLicenseKey.Text = lk
End Sub

Private Sub btnGenerateToken_Click
    Dim tk As String = LicenseUtils.Generate_EmailToken
    If tk = "" Then
        fx.Msgbox(frm,"Token was unable to be generated!","Warning")
        Return
    End If
    txtToken.Text = tk
End Sub

Private Sub btnCreateHTML_Click
    Dim email As String = lblUserEmail.Text
    Dim description As String = txtProductDescription.Text
    Dim version As String = lblProductVersion.Text
    Dim licensekey As String = txtLicenseKey.Text
    Dim token As String = txtToken.Text
    Dim issued As String = txtIssuedDate.Text
    Dim download_url As String = AppInfo.GetURL
    Dim folder As String = File.DirApp & "\licenses\"
    Dim filename As String = "softwarelicense_" & ProductName.ToLowerCase  & "_" & Firstname.ToLowerCase & "_" & LastName.ToLowerCase & ".html"
    Dim htmlfilename As String = folder & filename
    Dim html As String = Get_HTML_Template
    
    html = html.Replace("{firstname}",Firstname)
    html = html.Replace("{lastname}",LastName)
    html = html.Replace("{companyname}",CompanyName)
    html = html.Replace("{useremail}",email)
    html = html.Replace("{productname}",ProductName)
    html = html.Replace("{productdescription}",description)
    html = html.Replace("{productversion}",version)
    html = html.Replace("{licensekey}",licensekey)
    html = html.Replace("{issueddate}",issued)
    html = html.Replace("{year}",DateTime.GetYear(DateTime.Now))
    html = html.Replace("{download_url}",download_url)
    html = html.Replace("{token}",token)
    
    File.WriteString(folder,filename,html)
    txtHTMLFilename.Text = htmlfilename
    Log(htmlfilename)
    DBLicenses.License_Save_HTMLFilename(htmlfilename,LicenseID)
End Sub

Private Sub btnIssuedDate_Click
    txtIssuedDate.Text = Utils.GetDate
End Sub

Private Sub btnActivate_Click
    txtActivatedDate.Text = Utils.GetDate
End Sub

Private Sub btnInactivated_Click
    txtInactivatedDate.Text = Utils.GetDate
End Sub

Private Sub btnOpenHTML_Click
    Dim fn As String = txtHTMLFilename.Text
    If Not(File.Exists("",fn)) Then
        fx.Msgbox(frm,"HTML file not found!","Warning")
        Return
    End If
    fx.ShowExternalDocument(File.GetUri("",txtHTMLFilename.Text))
End Sub

Private Sub btnEmailSent_Click
    lblEmailSentDate.Text = Utils.GetDate
    DBLicenses.License_Save_SentEmailDate(lblEmailSentDate.Text,LicenseID)
    fx.Msgbox(frm,"Email Sent Date saved.","Attention")
End Sub

Sub Get_HTML_Template As String
    Dim html As String = File.ReadString(File.DirAssets,"request-apk-template.html")
    Return html
End Sub
#End Region

Please let me know what you find, as this is stopping me from moving forward.
 
Upvote 0

Swissmade

Well-Known Member
Licensed User
Longtime User
There are 2 forms: one with the TableView and the other is the edit form.

Here is the function that gets the info from the TableView:
B4X:
Private Sub tvLicenses_MouseClicked (EventData As MouseEvent)
    If EventData.ClickCount = 2 Then
        Dim tv As TableView = Sender
        Dim row() As Object = tv.SelectedRowValues
        If row <> Null Then
            UserID = row(1)
            License_Edit.LicenseID = row(0)
            License_Edit.UserID = row(1)
            License_Edit.ProductID = row(2)
            License_Edit.CustomerID = row(3)
            License_Edit.Fullname = row(4)
            License_Edit.ProductName = row(5)
            License_Edit.Show
        End If
    End If
End Sub

And here's the complete code from the edit form:
B4X:
'Static code module
Sub Process_Globals
    Private fx As JFX
    Private frm As Form
   
    Public LicenseID As Int
    Public UserID As Int
    Public Fullname As String
    Public CustomerID As Int
    Public ProductID As Int
    Public ProductName As String
   
    Private Firstname As String
    Private LastName As String
    Private CompanyName As String
   
    'User Information
    'Private cbxUser As ComboBox
    Private lblUserName As Label
    Private lblUserEmail As Label
    Private lblCompanyName As Label
   
    'License Information
    Private lblLicenseID As Label
    Private txtLicenseKey As TextField
    Private cbxProduct As ComboBox
    Private txtProductDescription As TextArea
    Private lblProductVersion As Label
    Private cbxStatus As ComboBox
    Private txtToken As TextField
    Private txtIssuedDate As TextField
    Private txtActivatedDate As TextField
    Private txtInactivatedDate As TextField
    Private txtHTMLFilename As TextField
    Private lblEmailSentDate As Label
End Sub

Public Sub Show
    If frm.IsInitialized = False Then
        frm.Initialize("frm", 900,845)
        frm.RootPane.LoadLayout("License_Edit")
    End If
   
    frm.SetWindowSizeLimits(900,845,1200,1000)
    frm.WindowLeft = (fx.PrimaryScreen.MaxX - frm.Width) / 2
    frm.WindowTop = (fx.PrimaryScreen.MaxY - frm.Height) / 2
   
    ClearForm
    LoadcbxProduct
    LoadcbxStatus
    SetTextColor
   
    If LicenseID <> 0 Then
        frm.Title = "Edit User License"
        LoadLicenseRecord
    Else
        frm.Title = "New User License"
        Get_User_Info
    End If
    frm.ShowAndWait
End Sub

#Region LOAD DATA
Sub ClearForm
    'User Info
    lblUserEmail.Text = ""
    lblCompanyName.Text = ""
   
    'License Info
    lblLicenseID.Text = "0"
    cbxProduct.SelectedIndex = -1
    txtLicenseKey.Text = ""
    cbxStatus.SelectedIndex = 0
    txtToken.Text = ""
    txtIssuedDate.Text = ""
    txtActivatedDate.Text = ""
    txtInactivatedDate.Text = ""
    txtHTMLFilename.Text = ""
    lblEmailSentDate.Text = ""
End Sub

Sub LoadcbxProduct
    cbxProduct.Items.Clear
    Dim data As List = DBProducts.Products_GetProductNames
    cbxProduct.Items.AddAll(data)
End Sub

Sub LoadcbxStatus
    cbxStatus.Items.Clear
    cbxStatus.Items.AddAll(Array As String("Issued","Activated","Inactivated"))
End Sub

Sub SetTextColor
    Utils.Set_TextField_TextColor(txtLicenseKey)
    Utils.Set_TextField_TextColor(txtToken)
    Utils.Set_TextField_TextColor(txtIssuedDate)
    Utils.Set_TextField_TextColor(txtActivatedDate)
    Utils.Set_TextField_TextColor(txtInactivatedDate)
    Utils.Set_TextField_TextColor(txtHTMLFilename)
    Utils.Set_TextArea_TextColor(txtProductDescription)
End Sub

Sub LoadLicenseRecord
    Dim l As LicenseView = DBLicenses.License_GetByLicenseID(LicenseID)
   
    If Not(l.IsInitialized) Then
        fx.Msgbox(frm,"Record not Found!","Warning")
        Return
    End If
   
    lblUserName.Text = l.Fullname
    cbxProduct.SelectedIndex = cbxProduct.Items.IndexOf(l.ProductName)
    cbxStatus.SelectedIndex = cbxStatus.Items.IndexOf(l.Status)
   
    'User Information
    Firstname = l.Firstname
    LastName = l.Lastname
    lblUserEmail.Text = l.UserEmail
    lblCompanyName.Text = l.CompanyName
    CompanyName = l.CompanyName
   
    'License Information
    lblLicenseID.Text = LicenseID
    txtProductDescription.Text = l.ProductDescription
    lblProductVersion.Text = l.ProductVersion
    txtLicenseKey.Text = l.LicenseKey
    txtToken.Text = l.Token
    txtIssuedDate.Text = l.IssuedDate
    txtActivatedDate.Text = l.ActivatedDate
    txtInactivatedDate.Text = l.InactivatedDate
    txtHTMLFilename.Text = l.HTMLFilename
    lblEmailSentDate.Text = l.EmailSentDate
End Sub

Sub Get_User_Info
    Dim u As UserView = DBUsers.User_GetByUserID(UserID)
    lblUserName.Text = u.Firstname.Trim & " " & u.Lastname
    lblUserEmail.Text = u.UserEmail
    lblCompanyName.Text = u.CompanyName
    cbxStatus.SelectedIndex = 0
End Sub

Private Sub cbxProduct_SelectedIndexChanged(Index As Int, Value As Object)
    ProductName = Value
    ProductID = DBProducts.Products_GetProductIDByName(ProductName)
    txtProductDescription.Text = DBProducts.Product_GetDescription(ProductID)
End Sub

'Private Sub cbxUser_SelectedIndexChanged(Index As Int, Value As Object)
'  
'End Sub

'Sub LoadcbxUsers
'    cbxUser.Items.Clear
'    Dim data As List = DBUsers.Users_GetUserNames(CustomerID)
'    data.RemoveAt(0)
'    cbxUser.Items.AddAll(data)
'    cbxUser.SelectedIndex = cbxUser.Items.IndexOf(Fullname)
'End Sub
#End Region

#Region BUTTONS
Private Sub btnSave_Click  
    Dim l As License
    l.Initialize
    l.LicenseID = LicenseID
    l.UserID = UserID
    l.ProductID = ProductID
    l.LicenseKey = txtLicenseKey.Text
    l.Status = cbxStatus.Value
    l.IssuedDate = txtIssuedDate.Text
    l.ActivatedDate = txtActivatedDate.Text
    l.InactivatedDate = txtInactivatedDate.Text
    l.Token = txtToken.Text
    l.HTMLFilename = txtHTMLFilename.Text
    l.EmailSentDate = lblEmailSentDate.Text
   
    'save data
    DBLicenses.License_Save(l)
    CallSubDelayed(Licenses,"LoadLicenses")
   
    fx.Msgbox(frm,"License saved. Now create the HTML file","Attention")
End Sub

Private Sub btnGenerateLicenseKey_Click
    Dim lk As String = LicenseUtils.Generate_LicenseKey
    If lk = "" Then
        fx.Msgbox(frm,"License Key was unable to be generated!","Warning")
        Return
    End If
    txtLicenseKey.Text = lk
End Sub

Private Sub btnGenerateToken_Click
    Dim tk As String = LicenseUtils.Generate_EmailToken
    If tk = "" Then
        fx.Msgbox(frm,"Token was unable to be generated!","Warning")
        Return
    End If
    txtToken.Text = tk
End Sub

Private Sub btnCreateHTML_Click
    Dim email As String = lblUserEmail.Text
    Dim description As String = txtProductDescription.Text
    Dim version As String = lblProductVersion.Text
    Dim licensekey As String = txtLicenseKey.Text
    Dim token As String = txtToken.Text
    Dim issued As String = txtIssuedDate.Text
    Dim download_url As String = AppInfo.GetURL
    Dim folder As String = File.DirApp & "\licenses\"
    Dim filename As String = "softwarelicense_" & ProductName.ToLowerCase  & "_" & Firstname.ToLowerCase & "_" & LastName.ToLowerCase & ".html"
    Dim htmlfilename As String = folder & filename
    Dim html As String = Get_HTML_Template
   
    html = html.Replace("{firstname}",Firstname)
    html = html.Replace("{lastname}",LastName)
    html = html.Replace("{companyname}",CompanyName)
    html = html.Replace("{useremail}",email)
    html = html.Replace("{productname}",ProductName)
    html = html.Replace("{productdescription}",description)
    html = html.Replace("{productversion}",version)
    html = html.Replace("{licensekey}",licensekey)
    html = html.Replace("{issueddate}",issued)
    html = html.Replace("{year}",DateTime.GetYear(DateTime.Now))
    html = html.Replace("{download_url}",download_url)
    html = html.Replace("{token}",token)
   
    File.WriteString(folder,filename,html)
    txtHTMLFilename.Text = htmlfilename
    Log(htmlfilename)
    DBLicenses.License_Save_HTMLFilename(htmlfilename,LicenseID)
End Sub

Private Sub btnIssuedDate_Click
    txtIssuedDate.Text = Utils.GetDate
End Sub

Private Sub btnActivate_Click
    txtActivatedDate.Text = Utils.GetDate
End Sub

Private Sub btnInactivated_Click
    txtInactivatedDate.Text = Utils.GetDate
End Sub

Private Sub btnOpenHTML_Click
    Dim fn As String = txtHTMLFilename.Text
    If Not(File.Exists("",fn)) Then
        fx.Msgbox(frm,"HTML file not found!","Warning")
        Return
    End If
    fx.ShowExternalDocument(File.GetUri("",txtHTMLFilename.Text))
End Sub

Private Sub btnEmailSent_Click
    lblEmailSentDate.Text = Utils.GetDate
    DBLicenses.License_Save_SentEmailDate(lblEmailSentDate.Text,LicenseID)
    fx.Msgbox(frm,"Email Sent Date saved.","Attention")
End Sub

Sub Get_HTML_Template As String
    Dim html As String = File.ReadString(File.DirAssets,"request-apk-template.html")
    Return html
End Sub
#End Region

Please let me know what you find, as this is stopping me from moving forward.
If possible send the project as zip.
Will check this tomorrow
 
Upvote 0

Mark Stuart

Well-Known Member
Licensed User
Longtime User
If possible send the project as zip.
Will check this tomorrow
I found the problem and was able to fix it.
All editable controls were in a Pane. Somehow the Pane: Enabled property was unchecked.
Checking it allowed all controls to be editable again.

Most likely me changing the wrong control.
Interesting thou, if you have this scenario, you can disable the Pane and not allow editing of any controls in it.
Nice feature if you want something like that.

Lesson learned: pay attention to what I'm doing.

Mark
 
Upvote 0
Top