Android Question [SOLVED] B4A Passing parameters between B4xPages

WhiteWizard

Member
Licensed User
I'm trying to pass some parameters between two B4Xpages, there's some example from Erel where you define a Sub in the destination page and calls its before invoke the Showpage method, however this works only from the MainPage, if you are executing something in the Page2 for ex., and want to call a Sub on the Page3, you have no access to the Page3 methods. Putting some variables in the Main module is an ugly solution.
 

LucaMs

Expert
Licensed User
It is a good practice to declare pages in the B4XMainPage Class_Globals as public.
This way you can access them from anywhere (and do it what you need in this case).
 
Upvote 0

WhiteWizard

Member
Licensed User
I've tried it but there's something that eludes my mind (in B4A):

B4XMainPage:
B4X:
Sub Class_Globals
    Private Root As B4XView 'ignore
    Private xui As XUI 'ignore
    Public txtUser As B4XFloatTextField
    Private btnLogin As B4XView
    Public Page2 As B4XPage2
    Public Page3 As B4XPage3
    Public PageIndicaciones As B4XPageIndicaciones
    Public PageFormIndicaciones As B4XPageFormIndicaciones
    Public PageFormIndicacionesMed As B4XPageFormIndicacionesMed
    Private txtPassword As B4XFloatTextField
    Private txtServerConfig As B4XFloatTextField
    Private txtExtServerConfig As B4XFloatTextField
    Private B4XLoadingIndicator1 As B4XLoadingIndicator
    Private LError As Label
    
    Public TransitionDuration As Int
End Sub

How do I access those instances?, if I'm inside B4XPage3 for example, I write "B4XMainPage." , "MainPage." , there's no way to access those members, I got no scope in B4A.
 
Upvote 0

WhiteWizard

Member
Licensed User
You can declare Public variables (V1) in absolutely any B4XPage (P2) and access that variable from any other B4XPage (P3) as long as you declare P2 in P3, then you can simply do something like P2.V1. Not a problem...
But if I declare one instance of B4XPage3 inside B4XPage2, and then set some public variables in B4XPage3, then invoke B4XPages.Show("Page3"), is the same class instance?,
 
Upvote 0

LucaMs

Expert
Licensed User
How do I access those instances?, if I'm inside B4XPage3 for example, I write "B4XMainPage." , "MainPage." , there's no way to access those members, I got no scope in B4A.
Public Page2 As B4XPage2
Public Page3 As B4XPage3
Public PageIndicaciones As B4XPageIndicaciones
Public PageFormIndicaciones As B4XPageFormIndicaciones
Public PageFormIndicacionesMed As B4XPageFormIndicacionesMed
All those pages will be accessible (obviously their declaration is not enough, you will also have to initialize them and add them to the B4XPages, so writing
B4XPages.AddPage("Page2", Page2) or B4XPages.AddPage("Page2ID", Page2)).

To access:
B4XPages.MainPage.Page2.YourSub
 
Last edited:
Upvote 0

aeric

Expert
Licensed User
Another way is to use GetPage.
Point #9 in tutorial.

B4X:
Page3 = B4XPages.GetPage("Page 3")
Page3.Button1.Text = "abc"
 
Last edited:
Upvote 0
Top