B4J Question Map question

madru

Active Member
Licensed User
Longtime User
Hi,

can somebody explain how to do an array or list of map?

this is the Java code I used, but I can't get it to work in B4J

B4X:
 public static Descriptor[] sg = new Descriptor[10];

int segptr = 0;

sg[segptr] = new Descriptor();
sg[segptr].segment = 1;

THX
 

stevel05

Expert
Licensed User
Longtime User
This works with descriptor as a type, it should be the same with any object or class.

B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Type Descriptor(Segment As Int)
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.SetFormStyle("UNIFIED")
    'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
    MainForm.Show
 
    Dim Sg(10) As Descriptor
    Dim Segptr As Int = 0
    Sg(Segptr).initialize
    Sg(Segptr).Segment = 1
 
End Sub
 
Upvote 0

madru

Active Member
Licensed User
Longtime User
Hi, thank you for your suggestion

I tried that before as a workaround, the main reason why I was after a map is the analysis of those in the code. With the TYPE solution I have to implement another method to do so. Not a big deal, but not nice as it breaks a little the concept of the code

it would be nice to declare a MAP in this way
B4X:
 Private Descriptor() as Map
- Erel?

THX
 
Upvote 0

madru

Active Member
Licensed User
Longtime User
Hi,

yes it is the same, all I was saying is that it would be nice to have such 'Map' functionality
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
If you use a Map it's contents could be an object of any type, you will have to read and assign an object to a variable of the correct type from the map before you can assign values to it's properties.

In an Array all it's elements have the type that you gave the array so you can access each elements properties directly.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…