B4J Question [SOLVED] Destroy custom class object.

Discussion in 'B4J Questions' started by jroriz, Jul 28, 2019.

  1. jroriz

    jroriz Active Member Licensed User

    Greetings.

    Is there a way to destroy a class after its initialization so that myclass.isinitialized returns false and the class can be initialized again?

    Code:
    Dim ct As ClassTest    ' my standard class module
    ct.Initialize

    'ct.destroy?
     
  2. XbNnX_507

    XbNnX_507 Active Member Licensed User

    if you Dim it again it will return false.
    Code:
    Dim ct As ClassTest  
    ct.Initialize
    ct.isinitialized 
    ' returns true

    Dim ct As ClassTest
    ct.isinialized 
    ' returns false
    There's not destructors in java hence nor in b4j.
     
    jimmyF and jroriz like this.
  3. jroriz

    jroriz Active Member Licensed User

    Thank you for the answer.

    It is actually a bit more complicated.

    I am using the class in an array declared as global.

    Code:
    Sub Process_Globals
        
    Private fx As JFX
        
    Private MainForm As Form
      
        
    Dim ct(4As ClassTest
    End Sub

    Sub AppStart (Form1 As Form, Args() As String)
        MainForm = Form1
        
    'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
      
      
        MainForm.Show

        ct(
    0).Initialize

        
    'ct(0).destroy or reinitialize
        'ct (1), ct (2) and ct (3) must remain intact.
      


    End Sub
    I thought of creating a temporary array, declaring the original array again, and copying the items from the temporary array I want to keep to it.
     
    Last edited: Jul 28, 2019
  4. XbNnX_507

    XbNnX_507 Active Member Licensed User

    Code:
    ls(0).Initialize
        
    Log(ls(0).IsInitialized ) 'True
        Dim ct As mClass
        ls(
    0) = ct
        
    Log( ls(0).IsInitialized ) 'False
     
    Peter Simpson and jroriz like this.
  5. jroriz

    jroriz Active Member Licensed User

    T
    Thats it!
     
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