B4J Question How to get a form programatically?

Dadaista

Active Member
Licensed User
Longtime User
Hi all
I created a form programatically but I don't know how to get it :oops:
 

Dadaista

Active Member
Licensed User
Longtime User
Hi Erel
Yes I saw the example a long time ago, but I can not see how solve my problem. When I push cancel button in my form I need to know the form where cancel button is placed and I do not know how to do that:oops:.
I can solve it with a global variable but I did not want that
I will continue investigating...
 
Last edited:
Upvote 0

EnriqueGonzalez

Expert
Licensed User
Longtime User
if you have many forms created programatically and therefore difficult to know where is the user, just create a List of the opened forms and check with a simple IF statement where is the user.

I did not tested the code below, may need some tweaking.

B4X:
Sub btn_Action
    Dim frm As Form = getForm(Sender)
End Sub

Sub getForm(childOfTheFormToFind As Node) As Form
    For Each frm As Form In listOfForms
        Dim joForm As JavaObject = frm
        Dim joStage As JavaObject = joForm.GetField("stage")
        If joStage = getNodeStage(childOfTheFormToFind) Then
            Return frm
        End If
    Next
   
    Return Null
End Sub

Sub getNodeStage(N As Node) As JavaObject
    If GetType(N.Parent).ToUpperCase = "STAGE" Then
        Return N.parent
    Else
        Return getNodeStage(N.Parent)
    End If
End Sub
 
Upvote 0
Top