Android Question Access to Main Views from a Module Code ?

Bluegyn

Member
Is it possible to control a VIEW (like an EditText) in a Sub, writen on a extra module of code in a project

I can easy do this by passing the EditText Object as paramater of the function

EXTRA CODE MODULE
B4X:
Sub MyFunction ( MyEdit As EditTExt)

MAIN
B4X:
EXTRA_CODE_MODULE.MyFonction ( EditText1 )


Is it a way to pass as argument the Whole MAIN Form ? like this :
B4X:
EXTRA_CODE_MODULE.MyFonction ( Me )

And how to get back VIEWS control in this remote function


Thanks
***{:-
 

Bluegyn

Member
Waouh ! another booklet to study !

Thank you for reply
I begin to feel the subtil spirit of this powerful language ...

***{:)
 
Upvote 0

Bluegyn

Member
About B4X (for newbie)

Is it an easy way to convert my first B4A project in B4X ?

Just copy and paste the right code in the right place ?
I suppose that just Move the B4A Files in B4A sub-folder will be hazardous ...

Is JAVA knowledge required for a beginner ?

***{:-
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
Just copy and paste the right code in the right place ?
I suppose that just Move the B4A Files in B4A sub-folder will be hazardous ...
If you are only targeting Android but using B4XPages like Erel suggested, after creating your new B4XPages do the following
  1. Files, I would personally click o the file manager and then click on Add Files (image below) to add your previous layouts and files
  2. Code modules, hmm because you will be adding B4XPages modules, I would just add the new B4XPages modules and copy and paste the code over (but that's me)
1620907952891.png


Is JAVA knowledge required for a beginner ?
No not at all


Enjoy...
 
Upvote 0

Bluegyn

Member
Thanks Peter,

Because I'm a Beginner, discovering the B4A, progressing slowly, step by step, I prefere starting with a brand new project, following the booklet. And as you suggest, Pasting and Runing the Old B4A Code, line by line, in the new B4X structure...

I've a small experience in "Pascal" with Delphi IDE, so I'm familiarized with the Objects & multi Form building, and try to find my old marks


Every day is a progress :'-)

***{:-
 
Upvote 0

Bluegyn

Member
Hello,

I come back after studying the B4X based on the "B4XPagesTwo/Three/pages" Booklet tutorial, and it works, but ...

The Initial AIM was to read a View Value from "One page to Another", without using activity (Or double Layout or Double Panel on a same page)

The most easy example is a B4XMainPage with a Label and a Button
And a second B4XPage1 with only a Label

What i want look like this :

B4XMAINPAGE

B4X:
Private label_MAIN As B4XView
Sub Button_MAIN_Click

  label_MAIN.txt = label_PAGE1.txt ' BUG !!!

End

I don't know where to declare the Label_Page1 to be seen by the MainPage
Or wat is the gateway to access the Label_PAGE1.txt from the MainPage routine in B4X

I swear that i've ride through the WWW forums before S.O.S.ing

***{:-
 
Upvote 0

Bluegyn

Member
Thank you Erel for giving me the light :'-)

I now find some difficulties to understand the subtility to declare a Page ID (string) to point a Layout (BAL) that allready has almost the "same" name.
I understand the necessity of linking 2 differents objects (BAS and BAL) because they are concretes with 2 features clearly separated. ID seam's to me a unusefull redondance?

I was hoping for something like this (without quotes) :
B4X:
Dim pg As B4XPage1 = B4XPages.GetPage(BAL_Page1.ID) 'change id

So I will do as you show me

Scope :
- Can you explain me this other subtility of the difference (or necessity) of sometimes declaring with "Dim" vs (Private or Public) ?

every day is a progress

***{:-
 
Upvote 0

Bluegyn

Member
The ThreePagesExample works fine to demonstrate the multipages gateway
With all the views available when I "Click" on the "page2" Object

YourPage.png


But when I do from my own

myPage.png


No "view" appears on the Help Combo

I've rewrite several time the whole project (copying each step from the example) and cannot break the deadlock
In what line is the evil hidden ??? :)

Thanks for helping The newbie
***{:-
 

Attachments

  • Project.zip
    17.8 KB · Views: 97
Upvote 0

klaus

Expert
Licensed User
Longtime User
The views you want to access from another module must be declared with Public or Dim.
In your case Label1 in the B4XPage2 module.
Then you will see it:

1621168227657.png
 

Attachments

  • ProjectNew.zip
    32.9 KB · Views: 100
Upvote 0

Bluegyn

Member
Bingo,

Thanks a lot, you save ly life ... :'-)

If I want a LABEL to be readable by an other B4XPage, I just have to declare It "Public" instead of default "Private" in the Class_Globals

***{:-
 
Upvote 0

Bluegyn

Member
Another question of a Newbie is How to pass (By REF) a Collection a VIEWS to un indepedant function

Imagine a MainPage and a separate Module of Code

The Mainpage has 2 EDIT : Edit_x and Edit_y
Le Module named MATHS has a Sub named Add and return X + Y

Passing Values (By Value) is very easy

MODULE CALC
B4X:
Sub Add ( x as float, y as float) as float
  return X+Y
End Sub

MAIN PAGE
B4X:
Private Z as Float = MATHS.Add ( x,y )


Passing VIEWS (By Ref) is easy too and allows the back-control over the Views to validate the correct Input

MODULE CALC
B4X:
Sub ADD ( Edit_X as B4XView, Edit_Y as B4XView , Label_Result As B4XView) as Boolean
' (return success or failed)

  If Edit_X = "" then
      Warning("Failing Data") 
      Edit_X.RequestFocus
      Return False
  End If

...

  Label_Result.Text = Edit_X.text + Edit_Y.Text

  Return True

End If


Now imagine that my MainPage contains plenty of Views with plenty of differents input values ...

I can pass the Plenty VIEWS as comma separated arguments, but I Would like better to pass the Whole MainPage

I tried the :

B4X:
MATHS.Calc ( Me )

Because I successly Use the same procedure in Pascal
B4X:
Uses MATHS;
Calc (Self);

But I don't know how to recover the View values and properties in the independant Sub ... ?


***{:-
 
Upvote 0

Bluegyn

Member
Hello

Solved the problem with "PUBLIC" Scope VIEWS on the Main Page

MainPage

B4X:
Public EditX As B4XView
Public EditY As B4XView
Public Result As B4XViex

Button1_Click
   CALC.Add ' No Args  !
End

CALC
B4X:
Sub Add
    Dim pg As B4XPage1 = B4XPages.GetPage("Page 1")       
    pg.Result.Text = pg.EditX.Text +pg.EditY.Text
End Sub

Thanks to you All
***{:-
 
Upvote 0
Top