B4J Question [SOLVED] Destroy custom class object.

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?

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

'ct.destroy?
 

XbNnX_507

Active Member
Licensed User
if you Dim it again it will return false.
B4X:
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.
 

jroriz

Active Member
Licensed User
if you Dim it again it will return false.
B4X:
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.
Thank you for the answer.

It is actually a bit more complicated.

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

B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
  
    Dim ct(4) As 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:
Top