iOS Question [SOLVED ?] - Copy and paste designer elements between B4A and B4I platforms

Sergio Haurat

Active Member
Licensed User
Longtime User
No matter which option I enter in the application, whenever it wants to load a new B4XPage in B4I, the execution breaks


*** frmxedituser: B4XPage_Created [mainpage]
Error occurred on line: 467 (AS_TextFieldAdvanced)
Target is null. Method called: _initialize:::

*** frmxfilter: B4XPage_Created [mainpage]
Error occurred on line: 53 (B4XComboBox)
Target is null. Method called: _initialize:::

Complete log error:
 
Solution
I finally got it working. This is my analysis, it is speculative and should be corroborated by trying to simulate what I write below in some other project.

If you start your development in B4A and need to make your version in B4I (or B4J), you can copy and paste all the components (text box, panel, image and other compatible elements) of a B4XPage, and thus not perform this design task twice.

You can click in the abstract designer area and press the key combination on the keyboard Control + A to "select all" and Control + C to "copy" to the clipboard.

You must go to the designer in B4I and in its B4XPage version press Control + V to “paste” the contents of the clipboard. As you can see in image 1, it selects all...

Alexander Stolte

Expert
Licensed User
Longtime User
Try to add a sleep(0) between addpage and showpage. In B4A only one panel has to be loaded, everything runs on a single activity. In B4I a new page is created each time, maybe it just takes a little more time which can be fixed with a sleep(0).
 
Upvote 0

Sergio Haurat

Active Member
Licensed User
Longtime User
Try to add a sleep(0) between addpage and showpage. In B4A only one panel has to be loaded, everything runs on a single activity. In B4I a new page is created each time, maybe it just takes a little more time which can be fixed with a sleep(0).
Unfortunately exactly the same thing happens

B4X:
Private Sub btnTabMenu_TabClick (Index As Int)
    Select Case btnTabMenu.GetTab(Index).xTab.Tag
        Case "ChartsDB"
            If Not (frmXCharts.IsInitialized) Then
                frmXCharts.Initialize
                B4XPages.AddPage("frmXCharts", frmXCharts)
            End If
            #IF B4I
            Sleep(0)
            #End If
            B4XPages.ShowPage("frmXCharts")
        Case "FixtureDB"
            If Not (frmXFixture.IsInitialized) Then
                frmXFixture.Initialize
                B4XPages.AddPage("frmXFixture", frmXFixture)
            End If
            #IF B4I
            Sleep(0)
            #End If
            B4XPages.ShowPage("frmXFixture")
        Case "LiveResultDB"
            If Not (frmXLiveResults.IsInitialized) Then
                frmXLiveResults.Initialize
                B4XPages.AddPage("frmXLiveResults", frmXLiveResults)
            End If
            #IF B4I
            Sleep(0)
            #End If
            B4XPages.ShowPage("frmXLiveResults")
        Case "CitationsDB"
            If Not (frmXCitations.IsInitialized) Then
                frmXCitations.Initialize
                B4XPages.AddPage("frmXCitations", frmXCitations)
            End If
            #IF B4I
            Sleep(0)
            #End If
            B4XPages.ShowPage("frmXCitations")
        Case "SN"
            If Not (frmXSN.IsInitialized) Then
                frmXSN.Initialize
                B4XPages.AddPage("frmXSN", frmXSN)
            End If
            #IF B4I
            Sleep(0)
            #End If
            B4XPages.ShowPage("frmXSN")
        Case "Filter"
            If Not (frmXFilter.IsInitialized) Then
                frmXFilter.Initialize
                B4XPages.AddPage("frmXFilter", frmXFilter)
            End If
            #IF B4I
            Sleep(0)
            #End If
            B4XPages.ShowPage("frmXFilter")
        Case "EditUser"
            If Not (frmXEditUser.IsInitialized) Then
                frmXEditUser.Initialize
                B4XPages.AddPage("frmXEditUser", frmXEditUser)
            End If
            #IF B4I
            Sleep(0)
            #End If
            B4XPages.ShowPage("frmXEditUser")
        Case "UserAttendance"
            If Not (frmXUserAttendance.IsInitialized) Then
                frmXUserAttendance.Initialize
                B4XPages.AddPage("frmXUserAttendance", frmXUserAttendance)
            End If
            #IF B4I
            Sleep(0)
            #End If
            B4XPages.ShowPage("frmXUserAttendance")
        Case "userDB"
            makeMenu("userDB")
        Case "Options"
            makeMenu("Options")
        Case "Settings"
            If AS_Properties.GetProperty("def_intFed").As (Int) <> -1 Then
                AS_Properties.PutProperty("app_intFed", AS_Properties.GetProperty("def_intFed").As (Int))
            End If
            If AS_Properties.GetProperty("def_intClub").As (Int) <> -1 Then
                AS_Properties.PutProperty("app_intClub", AS_Properties.GetProperty("def_intClub").As (Int))
            End If
            If clvContainer.GetBase.Visible = True Then
                clvContainer.GetBase.Visible = False
            End If
            asdbc_main.Show(True)
            imgBtnSettingsClose.Tag = "close"
        Case "padLockDB"
            Dim sf As Object = xui.Msgbox2Async(mdlFunctions.loc.Localize("started_win_app"), mdlFunctions.loc.Localize("app_name"), mdlFunctions.loc.Localize("yes"), "", mdlFunctions.loc.Localize("cancel"), Null)
            Wait For (sf) Msgbox_Result (Result As Int)
            If Result = xui.DialogResponse_Positive Then
                RunScanQR
            End If
        Case "back"
            makeMenu("main")
        Case "exit"
            Dim sf As Object = xui.Msgbox2Async(mdlFunctions.loc.Localize("exit_app"), mdlFunctions.loc.Localize("app_name"), mdlFunctions.loc.Localize("yes"), "", mdlFunctions.loc.Localize("cancel"), Null)
            Wait For (sf) Msgbox_Result (Result As Int)
            If Result = xui.DialogResponse_Positive Then
                Root.RemoveAllViews
                B4XPages.ClosePage(Me)
                #If B4A
                ExitApplication
                #End If
            End If
    End Select
End Sub

 
Upvote 0

Sergio Haurat

Active Member
Licensed User
Longtime User
Why not write frmXCharts.Initialize and B4XPages.AddPage("frmXCharts", frmXCharts) inside B4XPage_Created?
If you mean doing it within B4XMainPage, it's only to save memory usage resources. If a user, uses 3 out of 10 options, so that they are loaded? I've already tried to change to load all the pages in "created" and the problem is the same
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
If you mean doing it within B4XMainPage, it's only to save memory usage resources. If a user, uses 3 out of 10 options, so that they are loaded? I've already tried to change to load all the pages in "created" and the problem is the same
I don't think doing it in Created will takes up a lot of resources. I think it is the right way to do it. I think you should follow the tutorial on B4XPages.
 
Upvote 0

Sergio Haurat

Active Member
Licensed User
Longtime User
I don't think doing it in Created will takes up a lot of resources. I think it is the right way to do it. I think you should follow the tutorial on B4XPages.
I'll try again (I've already tried but without the sleep(0))
 
Upvote 0

Sergio Haurat

Active Member
Licensed User
Longtime User
I don't think doing it in Created will takes up a lot of resources. I think it is the right way to do it. I think you should follow the tutorial on B4XPages.



B4X:
Private Sub B4XPage_Created (RootView As B4XView)
    Root = RootView
    Root.LoadLayout("MainPage")


    If Not (frmXCharts.IsInitialized) Then
        frmXCharts.Initialize
        B4XPages.AddPage("frmXCharts", frmXCharts)
    End If
    If Not (frmXFixture.IsInitialized) Then
        frmXFixture.Initialize
        B4XPages.AddPage("frmXFixture", frmXFixture)
    End If
    If Not (frmXLiveResults.IsInitialized) Then
        frmXLiveResults.Initialize
        B4XPages.AddPage("frmXLiveResults", frmXLiveResults)
    End If
    If Not (frmXCitations.IsInitialized) Then
        frmXCitations.Initialize
        B4XPages.AddPage("frmXCitations", frmXCitations)
    End If
    If Not (frmXSN.IsInitialized) Then
        frmXSN.Initialize
        B4XPages.AddPage("frmXSN", frmXSN)
    End If
    If Not (frmXFilter.IsInitialized) Then
        frmXFilter.Initialize
        B4XPages.AddPage("frmXFilter", frmXFilter)
    End If
    If Not (frmXEditUser.IsInitialized) Then
        frmXEditUser.Initialize
        B4XPages.AddPage("frmXEditUser", frmXEditUser)
    End If


    #If B4I
    'AS_TabMenuAdvanced
    xpnl_bottom = xui.CreatePanel("")
    Root.AddView(xpnl_bottom, 0, 0, Root.Width, B4XPages.GetNativeParent(Me).SafeAreaInsets.Bottom)
    xpnl_bottom.Color = 0xFF202125
    'Wait For B4XPage_Resize (Width As Int, Height As Int)
    #End If

    'Localize
    mdlFunctions.loc.LocalizeLayout(Root)
    mdlFunctions.loc.ForceLocale("es")
    'Localize

    toast.Initialize(Root)
    'PUSH
    #if B4A
    CallSubDelayed2(FirebaseMessaging, "SubscribeToTopics", Array("general"))
    'request notification permission
    Wait For (CheckAndRequestNotificationPermission) Complete (HasPermission As Boolean)
    If HasPermission = False Then
        Log("no permission")
        toast.Show(mdlFunctions.loc.Localize("err_no_push_auth"))
    End If
    #End If
    'PUSH

    mdlFunctions.mapApps.Clear
    mdlFunctions.mapApps = clsFunct.GetIMApps
End Sub

B4X:
Private Sub btnTabMenu_TabClick (Index As Int)
    Select Case btnTabMenu.GetTab(Index).xTab.Tag
        Case "ChartsDB"
            #IF B4I
            Sleep(0)
            #End If
            B4XPages.ShowPage("frmXCharts")
        Case "FixtureDB"
            #IF B4I
            Sleep(0)
            #End If
            B4XPages.ShowPage("frmXFixture")
        Case "LiveResultDB"
            #IF B4I
            Sleep(0)
            #End If
            B4XPages.ShowPage("frmXLiveResults")
        Case "CitationsDB"
            #IF B4I
            Sleep(0)
            #End If
            B4XPages.ShowPage("frmXCitations")
        Case "SN"
            #IF B4I
            Sleep(0)
            #End If
            B4XPages.ShowPage("frmXSN")
        Case "Filter"
            #IF B4I
            Sleep(0)
            #End If
            B4XPages.ShowPage("frmXFilter")
        Case "EditUser"
            #IF B4I
            Sleep(0)
            #End If
            B4XPages.ShowPage("frmXEditUser")
        Case "UserAttendance"
            If Not (frmXUserAttendance.IsInitialized) Then
                frmXUserAttendance.Initialize
                B4XPages.AddPage("frmXUserAttendance", frmXUserAttendance)
            End If
            #IF B4I
            Sleep(0)
            #End If
            B4XPages.ShowPage("frmXUserAttendance")
        Case "userDB"
            makeMenu("userDB")
        Case "Options"
            makeMenu("Options")
        Case "Settings"
            If AS_Properties.GetProperty("def_intFed").As (Int) <> -1 Then
                AS_Properties.PutProperty("app_intFed", AS_Properties.GetProperty("def_intFed").As (Int))
            End If
            If AS_Properties.GetProperty("def_intClub").As (Int) <> -1 Then
                AS_Properties.PutProperty("app_intClub", AS_Properties.GetProperty("def_intClub").As (Int))
            End If
            If clvContainer.GetBase.Visible = True Then
                clvContainer.GetBase.Visible = False
            End If
            asdbc_main.Show(True)
            imgBtnSettingsClose.Tag = "close"
        Case "padLockDB"
            Dim sf As Object = xui.Msgbox2Async(mdlFunctions.loc.Localize("started_win_app"), mdlFunctions.loc.Localize("app_name"), mdlFunctions.loc.Localize("yes"), "", mdlFunctions.loc.Localize("cancel"), Null)
            Wait For (sf) Msgbox_Result (Result As Int)
            If Result = xui.DialogResponse_Positive Then
                RunScanQR
            End If
        Case "back"
            makeMenu("main")
        Case "exit"
            Dim sf As Object = xui.Msgbox2Async(mdlFunctions.loc.Localize("exit_app"), mdlFunctions.loc.Localize("app_name"), mdlFunctions.loc.Localize("yes"), "", mdlFunctions.loc.Localize("cancel"), Null)
            Wait For (sf) Msgbox_Result (Result As Int)
            If Result = xui.DialogResponse_Positive Then
                Root.RemoveAllViews
                B4XPages.ClosePage(Me)
                #If B4A
                ExitApplication
                #End If
            End If
    End Select
End Sub

It doesn't matter which menu icon you select and want to load to the B4XPage, in all cases in some component, it generates an error and the trigger is the "non-initialization" of something internal to iOS, from what I understand what the message says
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
The error seems to point to your frmXFilter - it looks like its trying to initialize a null object.
 
Upvote 0

Sergio Haurat

Active Member
Licensed User
Longtime User
The error seems to point to your frmXFilter - it looks like its trying to initialize a null object.
*** frmxedituser: B4XPage_Created [mainpage]
Error occurred on line: 467 (AS_TextFieldAdvanced)
Target is null. Method called: _initialize:::

No, in any form B4XPage generates the same error and in different components, I don't know if it is the first one that the designer loads
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
maybe as a check
Test if the component is null after the test for IsInitialized
 
Upvote 0

Sergio Haurat

Active Member
Licensed User
Longtime User
Not sure it is related.
Have you checked on B4XPage template that handles iOS safe area ?

I have the same code but it is originally related to the use of AS_TabMenuAdvanced


frmChartsPage:
Private Sub B4XPage_Created (RootView As B4XView)
    Root = RootView
    Root.LoadLayout("frmCharts")

    #If B4I
    'AS_TabMenuAdvanced
    xpnl_bottom = xui.CreatePanel("")
    Root.AddView(xpnl_bottom, 0, 0, Root.Width, B4XPages.GetNativeParent(Me).SafeAreaInsets.Bottom)
    xpnl_bottom.Color = 0xFF202125
    #End If
... continue

B4X:
Private Sub B4XPage_Resize (Width As Int, Height As Int)
#If B4I
    'AS_TabMenuAdvanced
    xpnl_bottom.SetLayoutAnimated(0,0,Height - B4XPages.GetNativeParent(Me).SafeAreaInsets.Bottom,Width,B4XPages.GetNativeParent(Me).SafeAreaInsets.Bottom)
    btnTabMenu.mBase.Top = Height - btnTabMenu.mBase.Height - B4XPages.GetNativeParent(Me).SafeAreaInsets.Bottom
#End If
End Sub
 
Upvote 0

Sergio Haurat

Active Member
Licensed User
Longtime User
I have the same code but it is originally related to the use of AS_TabMenuAdvanced
#If B4I
'AS_TabMenuAdvanced
xpnl_bottom = xui.CreatePanel("")
Root.AddView(xpnl_bottom, 0, 0, Root.Width, B4XPages.GetNativeParent(Me).SafeAreaInsets.Bottom)
xpnl_bottom.Color = 0xFF202125
#End If

Root = RootView
Root.LoadLayout("frmCharts")

In the example, the code for B4I is prior to loading the Layout, I am going to try inverting that segment of the code
 
Upvote 0

Sergio Haurat

Active Member
Licensed User
Longtime User
The same problem. There I reverted all the changes and verified the normal operation of B4A. Anyone with the B4I license and knowledge can privately share the original project with them without any problem.
 
Upvote 0

Sergio Haurat

Active Member
Licensed User
Longtime User
Hello everyone, I made this modification (AddPageAndCreate)

B4X:
Case "Filter"
    If Not (frmXFilter.IsInitialized) Then
        frmXFilter.Initialize
        B4XPages.AddPageAndCreate("frmXFilter", frmXFilter)
    End If
    B4XPages.ShowPage("frmXFilter")



I made a step in (F8) and it breaks on line 105. I don't know what to do @Erel. Do you think that by copying and pasting from one platform to another I made a mistake?
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
You can easily check this by clicking on a custom view and if the type does not contain the name of the view, but "Panel", then you know that something was wrong when you inserted it.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…