Android Question B4X Object property how to know if it exists

Favieri

Member
Hi all,

I have this code:
1638217067874.png

My problem is that not all objects have these properties. So how to test?
 

Favieri

Member
Erel, I'm sorry but I didn't know how to do it. newbies are a problem;)
Thanks, I tried several ways and found a way out.

Ta_bom(Portuguese) = Fine(English)

If objt Is Label Then tipo = "Label"
If objt Is Button Then tipo = "Button"
If objt Is EditText Then tipo = "EditText"
If objt Is ImageView Then tipo = "ImageView"
If objt Is Panel Then tipo = "Panel"

If tipo.EqualsIgnoreCase("panel") Or tipo.EqualsIgnoreCase("Button") Then carrgar = False

If carrgar Then

Log(tipo & "-" & objt.tag)
m.Put("Tipo", tipo)
m.Put("Tag", objt.tag)

If Funcoes.Ta_bom(objt, "Text") Then m.Put("Text" , objt.Text)
If Funcoes.Ta_bom(objt, "TextColor") Then m.Put("TextColor" , objt.TextColor)
If Funcoes.Ta_bom(objt, "TextSize") Then m.Put("TextSize" , objt.TextSize)
If Funcoes.Ta_bom(objt, "Top") Then m.Put("Top" , objt.Top)
If Funcoes.Ta_bom(objt, "Left") Then m.Put("Left" , objt.Left)
If Funcoes.Ta_bom(objt, "Width") Then m.Put("Width" , objt.Width)
If Funcoes.Ta_bom(objt, "Height") Then m.Put("Height" , objt.Height)
If Funcoes.Ta_bom(objt, "Color") Then m.Put("Color" , objt.Color)
If Funcoes.Ta_bom(objt, "Visible") Then m.Put("Visible" , objt.Visible)


Lista.Add(m)
My solution:

public Sub Ta_bom(Objeto As B4XView, Propriedade As String) As Boolean

Try
Select Propriedade
Case "Text"
Dim s As String = Objeto.text

Case "TextColor"
Dim s As String = Objeto.TextColor

Case "TextSize"
Dim s As String = Objeto.TextSize

Case "Top"
Dim s As String = Objeto.Top

Case "Left"
Dim s As String = Objeto.Left

Case "Width"
Dim s As String = Objeto.Width

Case "Height"
Dim s As String = Objeto.Height

Case "Color"
Dim s As String = Objeto.Color

Case "Visible"
Dim s As String = Objeto.Visible



End Select

Return True
Catch
Return False
End Try


End Sub




 
Upvote 0
Top