In B4XPages, I've been adding new pages with B4XPages.AddPages. What's the best way to see if a certain page ID already exists? If I try B4XPages.GetPage(id), it crashes, which I can Catch. But is there a simpler way?
In B4XPages, I've been adding new pages with B4XPages.AddPages. What's the best way to see if a certain page ID already exists? If I try B4XPages.GetPage(id), it crashes, which I can Catch. But is there a simpler way?
It's strange that I had to use a Try-Catch, because the GetPage function returns an object and should return Null if the page doesn't exist, but without that Try the project would crash.
Dim pg1 As page1
pg1.Initialize
If B4XPages.GetManager.FindPIFromB4XPage(pg1) = Null Then Log("Not added") Else Log("Added") 'Not added
B4XPages.AddPage("pg1", pg1)
If B4XPages.GetManager.FindPIFromB4XPage(pg1) = Null Then Log("Not added") Else Log("Added") 'Added
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
Dim pg1 As page1
pg1.Initialize
Log(isPageAdded(pg1)) 'false
B4XPages.AddPage("pg1", pg1)
Log(isPageAdded(pg1)) 'true
End Sub
Private Sub isPageAdded(pge As Object) As Boolean
Return Not(B4XPages.GetManager.FindPIFromB4XPage(pge) = Null)
End Sub
One day I asked EREL how many pages can be added, for memory reasons, and he answered something like A LOT (I understood that I shouldn't worry about that). So I load all of them when I start my application and then forget if they are there or not. But of course, this question may be appropriate
One day I asked EREL how many pages can be added, for memory reasons, and he answered something like A LOT (I understood that I shouldn't worry about that). So I load all of them when I start my application and then forget if they are there or not. But of course, this question may be appropriate
Thank you very much for the clarification.
I just do the
B4XPages.AddPage
and when I need it
B4XPages.ShowPage("pagenname")
I have never used AddPageAndCreate and I must admit that I did not know about it.
As I see, this also causes the B4XPage_Created code to be executed
which can be very interesting.
When the form is launched, this event will already be executed and only the
Private sub B4XPage_Appear
Now I understand better the reason for this question.