Android Question Accessing objects from different modules

özer yılmaz

Member
Licensed User
I am using Map (MainMap) on each line for CustomListView1 within the THSLT module. But I need to access CustomListView1 and Map (MainMap) content from the other module (ODM). As I read and understand in the forum, there is no direct access to the object. I hope the following example shows my problem. I would be glad if you help
'----------------------------------------------------------------------------------
module --> THSLT

MainMap.Put("Urun" , "ALBM")
MainMap.Put("UrunKod" , "1")
MainMap.Put("FisNo" , FisNo_)
MainMap.Put("Birim" , "Adet")
MainMap.Put("Miktar" , "1")
MainMap.Put("BarkodNo" , BarkodNo)
MainMap.Put("Grupad" , SiparisTur_ )
MainMap.Put("GrupKod" , "1")
MainMap.Put("Tutar" , TahsilEdilecek)
CustomListView1.Add(CreateListItem( MainMap.Get("Urun") , CustomListView1.AsView.Width, 110dip), 110dip, MainMap)

'----------------------------------------------------------------------------------
module --> ODM

Dim FisNo As String
Dim BarkodNo As String
For i = 0 To THSLT.CustomListView1.GetSize - 1
Dim Map As Map
Map.Initialize( )
Map = THSLT.CustomListView1.GetValue(i)
FisNo = Map.Get("FisNo")
BarkodNo = Map.Get("BarkodNo")
'----------
'I'll do SQL INSERT here.
'----------
Next
'---------------------------------------------------------------------------------
 
Last edited:

özer yılmaz

Member
Licensed User
Thank you for your answer but I don't understand it. Are you saying I can access the object from other modules when I define Public in Globals? Can you write a tiny example?
--------------------------------------------------------------
module --> THSLT

Sub Globals
Public CustomListView1 As CustomListView
End Sub
----------------------------------------------------
module --> ODM
THSLT.CustomListView1
----------------------------------------------------
 
Upvote 0

Brandsum

Well-Known Member
Licensed User
Thank you for your answer but I don't understand it. Are you saying I can access the object from other modules when I define Public in Globals? Can you write a tiny example?
--------------------------------------------------------------
module --> THSLT

Sub Globals
Public CustomListView1 As CustomListView
End Sub
----------------------------------------------------
module --> ODM
THSLT.CustomListView1
----------------------------------------------------
Yes, that is how you can access.
 
Upvote 0

özer yılmaz

Member
Licensed User
from another module; I can't reach any object under globals even though I make private. Now that you've confirmed it will work, you're working. This may be caused by my inaccessibility. Is there anything to do with the B4a 9.30 version?
 
Last edited:
Upvote 0

Brandsum

Well-Known Member
Licensed User
from another module; I can't reach any object under globals even though I make private. Now that you've confirmed it will work, you're working. This may be caused by my inaccessibility. Is there anything to do with the B4a 9.30 version?
Sorry for posting the wrong information. You can't directly access the activity object from other modules. You have to declare another variable in Process Global which will hold the size of CLV. Then you can call that process global variable from another module.
 
Upvote 0

Brandsum

Well-Known Member
Licensed User
I got a little something. Can you apply it on this?
Please use Export functionality of IDE to export project and upload it to the forum. As I can see there is no Starter.Bas file inside the zip.

And why are you using a blank activity module? If you want to do some work which is not related to activity then use Code/Class module.

In this case, if you want to access the values of a CLV / any list from another activity then
  1. create a process global variable (list) in that activity or in starter service.
  2. feed that list variable when you are inserting the CLV items.
  3. pull that list variable whenever you need in any module.
B4X:
'Create a process global vairable in Starter service
Sub Process_Globals
    Public list_variable As List
End Sub

Sub Service_Create
    list_variable.Initialize
End Sub


'Feed that list while adding CLV items
'(as per your code)
For i = 1 To 100
    Dim myMap As Map
    myMap.Initialize
    myMap.Put("value1",  $"First value for Item #${i}"$)
    myMap.Put("value2",  $"Second value for Item #${i}"$)      
    myMap.Put("value3",  $"value #${i}"$)
    'myMap.Put (......................

    Starter.list_variable.Add(myMap) ' <- this

    CustomListView1.Add(CreateListItem($"First value for Item #${i}"$, CustomListView1.AsView.Width, 80dip), 80dip, myMap)      
Next  


'From any activity/Module use that list variable instead of CLV
'(as per your code)
Dim FisNo As String
For i = 0 To Main.CustomListView1.GetSize - 1
    Dim Map As Map = Starter.list_variable.Get(i) '<-this
    FisNo = Map.Get("value3")
    Msgbox(FisNo,"")  
Next

But first, clear your concept.
 
Upvote 0
Top