B4J Question [b4j] new data type

jinyistudio

Well-Known Member
Licensed User
Longtime User
Hi

I define a data type as :
B4X:
Type thdfunction(name As String,param() As Object)

when i use it as :
B4X:
Public Sub Assigned(fnName As String,fnParam() As Object)
    Dim obj As thdfunction   
    obj.name =fnName
    obj.param = fnParam   
End Sub

But I found it has Initialize and Initialized too. Could i use them(Initialize and Initialized) in program ?
 

LucaMs

Expert
Licensed User
Longtime User
Usually you should initialize the object; I don't remember why, but you could set the values of members even if you do not initialize the object, but, anyway, it is a bad practice.

The property IsInitialized is useful to know (to check) if the object has already been initialized, after its declaration.


I suppose that your Assigned routine (which name should be Assignment, I think) is only an example, because I cannot understand its purpose, as it is.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
when i use it as
Then it will probably not work.
You are dimming a new Objectinstance but you are not returning it from the sub. So the variable will be discarded at the end of the sub.

B4X:
Public Sub Assign(fnName As String,fnParam() As Object) As thdfunction
    Dim obj As thdfunction  
    obj.initialize
    obj.name =fnName
    obj.param = fnParam  
    return obj
End Sub
 
Upvote 0
Top