Bug? RandomAccessFile.WriteObject for List have activity Obj.

Discussion in 'Bugs & wishlist' started by xky, Dec 30, 2017.

Tags:
  1. xky

    xky Member Licensed 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.
     
  2. LucaMs

    LucaMs Expert Licensed User

    I do not think this can happen "automatically", only if you have added an activity to your class instance (perhaps a reference, a variable).

    Can you post the source code?
     
  3. xky

    xky Member Licensed User

    upload_2017-12-30_22-52-50.png
    Code:
    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
    Code:
    #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
     
  4. xky

    xky Member Licensed User

    this is a sample.
    You can add breakpoint on Msgbox(...)
     

    Attached Files:

  5. Erel

    Erel Administrator Staff Member Licensed User

  6. xky

    xky Member Licensed 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.
     
  7. LucaMs

    LucaMs Expert Licensed User

    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: Dec 31, 2017
  8. xky

    xky Member Licensed User

    RAF.WriteObject(lsL) can write lsL correctly? and RAF.ReadObject() can read the list back?
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    What is IsL?

    Why are you using ReadObject instead of ReadB4XObject / WriteB4XObject?
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice