B4J Question Is there a way to do this? (

Marc De Loose

Member
Licensed User
Longtime User
It would simplify the code. If I could do something like this.

B4X:
private sub whatever   
        Private xTest As B4XView = lst_xRotateKnobs.Get(i)
        If xTest Is xRotateKnob Then
            Public xObject As xTextField
            
        Else If xTest Is xTextField Then
            Public xObject As xRotateKnob
        End If
        
        ' do stuff with the resulting xObject'
        
end sub
 

aeric

Expert
Licensed User
Longtime User
Do you get any error?
B4X:
private sub whatever  
        Dim xTest As Object = lst_xRotateKnobs.Get(i)
        If xTest Is xRotateKnob Then
            Dim xObject As xRotateKnob = xTest
           
        Else If xTest Is xTextField Then
            Dim xObject As xTextField = xTest
        End If
       
        ' do stuff with the resulting xObject'
       
end sub
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
No you cannot do it that way.
1. Because xRotaryKnob is not a B4XView.
2. You will get this error: 'Current declaration does not match the previous one'. You need to give it a different name.

For point1 you got a solution.
But it does not solve the second one, you need a different name.

Do you have a concrete example on what exactly you want to do ?
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…