Android Question B4XPages with BCtextengine

james_sgp

Active Member
Licensed User
Longtime User
I`m having problems with BCtextengine on the B4XMainPage of my app. I have a BBCodeView on my form (everything works fine without this).

<Code
B4X:
Class_Globls

     Private slash_lbl As BBCodeView
    Public bc As BCTextEngine
...

Private Sub B4XPage_Created (Root1 As B4XView)
    
    bc.Initialize (Root1)
    
    slash_lbl.Text = $"[b]HELLO[/b]"$
...

the last line gives me an error when run:

Error occurred on line 99 (B4XMainPage) -> Line 99 is the Private Sub B4XPage_Created, End Sub statement
java.lang.Exception: array not expected

I`m sure I`m made a silly mistake but I can`t see it for the life of me.

Thanks James
 

LucaMs

Expert
Licensed User
Longtime User
Your slash_lbl must be a BBCodeView added to a layout you load (in Root1 or elsewhere); did it?

B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    
    bc.Initialize (Root1)
    slash_lbl.Text = $"[b]HELLO[/b]"$
'...

Layout "MainPage" contains a BBCodeView named "slash_lbl".
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
I'm still working on the combination of BCtextengine, the Drawer sliding menu and B4XPages in B4J and B4A. It was not so simple for me to get it working. The hardest part for me was finding the trick for the initialization of the BCtextengine within the show routine and setting the correct panel dimensions over the main page by using the Base variable. I have it now working in B4J and B4A. My next step is to remove the "overlay" panel when I close the BCtextengine B4Xpage.

Initialization of BCtextengine:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    
    Private BBCodeView1 As BBCodeView
    Private TextEngine As BCTextEngine
    Private BBLabel1 As BBLabel
    
    Private Base As B4XView
    Private PanelFileNameStr As String = "PrivacyIntro.txt"
    Private PanelNameStr As String = "Introductie"
    
End Sub

Public Sub Show (Parent As B4XView)
    Base = Parent
    If Root.IsInitialized = False Then
        InitView
    End If

    Root.RemoveViewFromParent
    
    Parent.AddView(Root, 0dip, 40dip, B4XPages.MainPage.LayoutWidth, B4XPages.MainPage.LayoutHeight)
'    Parent.AddView(mBase, 0, 0, 100%x, 100%y)
    
'    TextEngine.Initialize(Root)
    TextEngine.Initialize(B4XPages.MainPage.Drawer.CenterPanel)
    BBCodeView1.TextEngine = TextEngine
    BBCodeView1.mBase.Height = Base.Height - 110dip
    BBCodeView1.mBase.Width = Base.Width -25dip
    BBCodeView1.mBase.Top = Base.Top + 95dip
    Log($"BBCodeView1.mBase.Width = ${BBCodeView1.mBase.Width}"$)
    
    BBLabel1.mBase.Top = Base.Top + 45dip

    Dim btn As Button
    #if B4i
    btn.Initialize("btn", btn.STYLE_SYSTEM)
    #Else If B4J or B4A
    btn.Initialize("btn")
    #End If
    Dim xbtn As B4XView = btn
    If xui.IsB4i Then xbtn.SetColorAndBorder(xui.Color_Transparent, 1dip, xui.Color_Black, 2dip)
    xbtn.Text = "Click!"
    xbtn.SetLayoutAnimated(0, 0, 0, 100dip, 40dip)
    Dim pnl As B4XView = xui.CreatePanel("")
    pnl.SetLayoutAnimated(0, 0, 0, 200dip, 120dip)
    BBCodeView1.Views.Put("btn", btn)
    
    Dim Msg As String = File.ReadString(File.DirAssets, PanelFileNameStr)
'    Log(BBCodeView1.Text)
'    Log(Msg)
    
    BBCodeView1.Text = Msg
    B4XPages.MainPage.lblDashboardTitle.Text = "App - " & CallSub(Me,"GetName")
    BBLabel1.Text = $"[FontAwesome=0xF17B size=30/] This is a [b]BB[color=0xff006688]Label[/color][/b] [img FileName="logo.png" height=30 vertical=8/]"$
End Sub

Private Sub InitView
    Root = xui.CreatePanel("")
'    Root.LoadLayout("Introduction")
    B4XPages.MainPage.Drawer.CenterPanel.loadLayout("Introduction")
    
    TextEngine.Initialize(B4XPages.MainPage.Drawer.CenterPanel)
    
    BBCodeView1.TextEngine = TextEngine
End Sub

1623047241330.png
1623047481965.png
 
Upvote 0

james_sgp

Active Member
Licensed User
Longtime User
Your slash_lbl must be a BBCodeView added to a layout you load (in Root1 or elsewhere); did it?

B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
   
    bc.Initialize (Root1)
    slash_lbl.Text = $"[b]HELLO[/b]"$
'...

Layout "MainPage" contains a BBCodeView named "slash_lbl".

I added the BBCodeView (slash_lbl) in the designer.

James
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
I mean i had originally already added the BBCodeView in the designer. And was getting the problem.

James
Sometimes it helps to delete the global variable and reapply it from the designer.
 
Upvote 0

james_sgp

Active Member
Licensed User
Longtime User
Ok, in creating a small project; I found the problem (thanks Erel). The line where I was assigning the text to the BBCodeView was after the section where I initialized/added the other B4XPages in my B4XMainPage. Once I move the line before these, everything worked...

I`m new to B4XPages and still learning...thanks everyone for comments.
 
Upvote 0
Top