Bug? RandomAccessFile.WriteObject for List have activity Obj.

xky

Member
Licensed User
Longtime User
In an Activity with List.Add(Obj), when the Obj is a instance of a class, in the Obj members will have a member that is the activity, why?

For example:

Class CL
a as int
b as int
Class end

if the instance of CL is ICL
in ICL that are:
a
b
Activity (Why have it?)

when use list.add(ICL) to a list, the list will have a member ICL that have the activity member.
So, if use RandomAccessFile.WriteObject(List,true,0) it can write successful.(I think it is not successful because it can't write a activity) but when use RandomAccessFile.ReadObject(0), it can't read out the List.
 

xky

Member
Licensed User
Longtime User
upload_2017-12-30_22-52-50.png

B4X:
Sub Class_Globals
    Dim a As Int
    Dim b As Int
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize

End Sub
B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim CL1 As CL
    Dim lsL As List
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    CL1.Initialize
    lsL.Initialize
End Sub

Sub Activity_Resume
    CL1.a=1
    CL1.b=2
    lsL.Add(CL1)
    Msgbox("OK","")
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
 

xky

Member
Licensed User
Longtime User
this is a sample.
You can add breakpoint on Msgbox(...)
 

Attachments

  • Test.zip
    8.9 KB · Views: 351

xky

Member
Licensed User
Longtime User
I mean that I did't put the Class instances in my instance, but it appear in my instance automaticly. I only have a,b the 2 int in my instance.
 

LucaMs

Expert
Licensed User
Longtime User
In an Activity with List.Add(Obj), when the Obj is a instance of a class, in the Obj members will have a member that is the activity, why?
The Activity you see is in your project (Debug-Watch window) is not in your CL1 object and then not event in your lsL list; you can see Activity also in a new empty project.

Your object in your List is the one in the array, indicated by the arrow:
upload_2017-12-31_19-15-16.png



However, the whole tree is not very clear, since the objects at first level are of different type but they have the same icon, in the array (the list) you can not seee the name of your object (CL1) and because it contains "starter" and "main" (probably references for internal purpose).
 
Last edited:

xky

Member
Licensed User
Longtime User
RAF.WriteObject(lsL) can write lsL correctly? and RAF.ReadObject() can read the list back?
 
Top