Android Question Converting from B4A to B4XPages

johnaaronrose

Active Member
Licensed User
Longtime User
I've read the booklet entitled "Converting B4A Projects to B4XPages". But I have some queries, perhaps due to my misunderstanding parts of them:
1. On my apps developed in B4A, if I remember correctly I didn't code anything in Starter.bas but I somehow started an app somewhere else. Thus when I converted my projects (i.e. apps) in 2022, I had a Starter.bas with nothing in it apart from coding supplied as standard and the 'start' coding went into B4XMainPage. I've since found out today that I can remove & delete the Starter.bas module in each app. I've done that and the apps work OK. On some of my projects, I have the various .bas modules in the project folder and on some I have the .bas modules in the B4A sub-folder of the project folder. Which is correct?
2. On one (B4A converted to B4X) project, I have an SQLite database file with a .db extension held on my box.com account and the app copies it to a directory after downloading it (unless the database file already exists in that directory). I'm confused about which directory is the best one that it should be copied to. Is xui.defaultfolder the best one?
3. If I wanted to have my B4A project also developed for B4J, what are the implications:
a. in terms of the Additional Libraries, I noticed in a booklet that some B4A Views (e.g. ScrollView2D) are not available in B4J, Any ideas?
b. will all the coding in B4A's .bas files work for B4J?
 
1. On my apps developed in B4A, if I remember correctly I didn't code anything in Starter.bas but I somehow started an app somewhere else. Thus when I converted my projects (i.e. apps) in 2022, I had a Starter.bas with nothing in it apart from coding supplied as standard and the 'start' coding went into B4XMainPage. I've since found out today that I can remove & delete the Starter.bas module in each app. I've done that and the apps work OK. On some of my projects, I have the various .bas modules in the project folder and on some I have the .bas modules in the B4A sub-folder of the project folder. Which is correct?
You need to place B4A-specific .bas modules in the B4A folder, while shared modules—those used by other platforms (B4J, B4i)—must be placed in the parent folder (let's call it the "root" folder), and you must reference them within the B4A project.

For example, if you create a new class or code module that also needs to be used by B4i and/or B4J:

1789574497418.png


By doing so, MyNewClass.bas will NOT be placed in the B4A folder but in the project's main folder, and in the IDE you will see:
1789574611003.png


That "(..)" actually means the .bas file is located elsewhere on your PC—in this case, in the project's main folder; it acts as a sort of link to the .bas file.

(What a terrible explanation 😁 . I'm in too much of a rush.)


It is also important to understand this when adding a file that already exists on your PC:
1789574883527.png


- Copy to project folder will copy the .bas file to B4A (because this example is B4A)
- Copy to parent folder will copy it to the "main" folder of the B4XPages project
- Links 1 and 2 are clear enough, right?


2. On one (B4A converted to B4X) project, I have an SQLite database file with a .db extension held on my box.com account and the app copies it to a directory after downloading it (unless the database file already exists in that directory). I'm confused about which directory is the best one that it should be copied to. Is xui.defaultfolder the best one?
Yes.



3. If I wanted to have my B4A project also developed for B4J, what are the implications:
a. in terms of the Additional Libraries, I noticed in a booklet that some B4A Views (e.g. ScrollView2D) are not available in B4J, Any ideas?
b. will all the coding in B4A's .bas files work for B4J?

A great deal of code is compatible across B4A, B4I, and B4J.
Naturally, compatibility is even greater between B4A and B4I, as both are designed for mobile.

It is important to use cross-platform Views whenever possible; their names usually begin with "B4X," and you can search for them on the site by applying a filter:
1789575608781.png


Mainly "XUI Views" (library)


Furthermore, you should use libraries or classes specifically designed to smooth out the differences.

1789575802031.png
 
Last edited:
Upvote 1
Complement to the post above.

1. On some of my projects, I have the various .bas modules in the project folder and on some I have the .bas modules in the B4A sub-folder of the project folder. Which is correct?
It depends on what kind of .bas modules you are speaking of.
In my mind all .bas modules should be cross-platform and therefore in the main project folder and not in the project specific folder.

2. I'm confused about which directory is the best one that it should be copied to. Is xui.defaultfolder the best one?
If you want to use the database only in your application, xui.defaultfolder is the right place.
If the database needs to be accessed from outsides your application, you might consider to use RunTimePermissons library
and use RunTimePermissons.GetSafeDirDefaultExternal. This folder is accessible with the Windows FileExplorer from a PC connected vie USB.

3a. Each platform has its specific objects.
ScrollView2D is a special case.
In B4A there is no native object allowing scrolling in both directions.
The ScrollView2D object in B4A is equivalent to ScrollPane in B4J and ScrollView in B4i, but the events are different.
You can define platform specific code with:
B4X: Copy
#If B4J
    'B4J code
#Else If B4A
    'B4A code
#Else If B4i
    'B4i code
#End If
With this, your code remains multi-platform.

3b. will all the coding in B4A's .bas files work for B4J?
Yes and No, if you use B4A specific code it will not work.
Declare your views as B4XView instead of platform specific objcets like Label, Panel / Pane, Button, EditText / TextField etc.
Use where ever you can XUI methods.
 
Upvote 1

Similar Threads

Replies
8
Views
17K
Replies
2
Views
13K
Replies
22
Views
42K
  • Locked
  • Article Article
Replies
4
Views
23K
Back
Top