B4J Question [ABMaterial] How can I go through all the components of the modal form?

Gabino A. de la Gala

Active Member
Licensed User
Longtime User
I am preparing a modal form and I would like to automate as much as possible the relation of the ABMIntput components with the fields that I am adding in the map and then update the table.

Is there any way to go through all the components of the modal form ask for the type they are and if they are ABMInput take the .text .id to make a .put in the field map to update?

Thank you.
 

Gabino A. de la Gala

Active Member
Licensed User
Longtime User
I am now starting from all the fields obtained from the database and searching for the corresponding ABMInput (but it is poorly optimized since I will usually get many more fields than those defined in the form)

B4X:
...
   Dim ResgistroEditado AS Map
   RegistroEditado = Registros.Get(0)
...
    Dim inp As ABMModalSheet
    inp = page.ModalSheet("inp")
    Dim InputAux As ABMInput
    Dim CamposModificados As Map
    CamposModificados.Initialize
    Dim i As Int
    For i = 0 To RegistroEditado.Size -1
        'Log(RegistroEditado.GetKeyAt(i) & " - " & RegistroEditado.GetValueAt(i))
        Try
            InputAux = inp.Content.Component("inp"&RegistroEditado.GetKeyAt(i))
        Catch
            Log("No encontrado")
        End Try
        If (InputAux <> Null) Then
            If ABMShared.NullToStr_(RegistroEditado.GetValueAt(i)) <> InputAux.Text Then
                Log("Detectada diferencia: " & InputAux.Text)
                CamposModificados.Put(RegistroEditado.GetKeyAt(i), InputAux.Text)
            End If
        End If
    Next
   
    If CamposModificados.Size > 0 Then             ' Hubo campos modificados
        Dim CamposClave As Map 
        CamposClave.Initialize
        CamposClave.Put("codigo", RegistroEditado.Get("codigo"))
        ModuloDatos.SQLUpdateRecord2(ModuloDatos.Sql1, "Cli$E", CamposModificados, CamposClave, ws)
    End If

And what I would like, would be to do it the other way around.
Go through all the ABMInput objects that I have in the form, starting from its id, update the corresponding key in the map with which I will then make the update.
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
@Gabino A. de la Gala You posted in the feedback app: 'would like to automate as much as possible the relation of the ABMIntput components with the fields that I am adding in the map'

This is something you have to be careful with! Running the method (page).component() BEFORE getting the .text property has an very important functionality. It doesn't only get you the ABMComponent (this is just the java/B4J part) put this command also makes sure the component you get back is up to date with its counterpart in the browser. So do not put the component itself in the map, just its ID and when you need it, use .Component(id).
 
Upvote 0
Top