Android Question Class IsInitialized

Saverio

Member
Licensed User
Longtime User
Hello there,

The code I'm using is:
B4X:
'Class module
Private Sub Class_Globals

    'this override the original Class method isInitialized()
    Private IsInitialized As Boolean = False

End Sub

'Property
Public Sub getinitialized As Boolean
    Return IsInitialized
End Sub

'Initializes the object
Public Sub Initialize
  Try
     '// Do Some Code Here
    IsInitialized = True

  Catch
   ToastMessageShow(" Class1: Can't Initialize", True)
  End Try
End Sub
B4X:
'Main module
sub SomeSub

  dim myClass As Class1

  log(myClass.initialized)

  myClass.Initialize

  log(myClass.initialized)

end sub

In this way I can control the real state of a class. Othewise, the class will return ever true.
For me It's working perfectly.
But, I'd like to know if it could be a problem.

Erel?

Thanks
 
Last edited:

Saverio

Member
Licensed User
Longtime User
Why don't you use the built-in IsInitialized property?
It return ever True. Even the things, inside Class1.Initialize, in a Try block, went wrong or not(Exception).
With the way of the above example, at least, I can control the class initialization, as I coded it.
Remain the fact that any suggestion will be welcome
 
Upvote 0
Top