B4J Question Initialize not found in map Contain form as value

invocker

Active Member
I add a form as value in map and i get error when need to initialze the form How resolve it

B4X:
B4XPages.MainPage.OpenForm.As(Form).Initialize("Svcfrm",600,400)

Error
java.lang.RuntimeException: Method: Initialize not found in: anywheresoftware.b4a.objects.collections.Map$MyMap
 
Solution
B4X:
If B4XPages.Main.OpenForms.Contains(c) Then
 Dim frm As Form = B4XPages.MainPage.OpenForm.Get(c)
 ...
 frm.Title = ".."
 B4XPages.Main.OpenForms.Remove(c)
End If

Your code is correct but not very elegant. See my code for correct usage of maps.

invocker

Active Member
openform is a map
project client server , that need to open process form and contact form ... for each client and when client disconnect ,thein their form close also

I can resolve this issue with initialize a form first and add to map but need more powerfull method
 
Upvote 0

invocker

Active Member
Your code is wrong.
If OpenForm is a Map then there is no meaning to OpenForm.As(Form). I guess that you are missing a Get call:
B4X:
OpenForm.Get("some form").As(Form)...
thank you mr erel it is work now , how can use it for close a form if client disconnect I use it like this but not work perfect

B4X:
Public Sub Show(info As Map,c As Client)
    checklistsize
    If  B4XPages.MainPage.OpenForm.Size>0 Then
        For Each s As Client In  B4XPages.MainPage.OpenForm.Keys
            If s = c Then
            B4XPages.MainPage.OpenForm.Get(s).As(Form).Close
                B4XPages.MainPage.OpenForm.Remove(s)
                checklistsize
                B4XPages.MainPage.OpenForm.Put(s,Svcfrm) 'add form with client astream as key
                B4XPages.MainPage.OpenForm.get(s).As(Form).Initialize("form",600,400)
                B4XPages.MainPage.OpenForm.get(s).As(Form).RootPane.LoadLayout("ServicesLay")
                B4XPages.MainPage.OpenForm.get(s).As(Form).Title="Services Manager "
                B4XPages.MainPage.OpenForm.get(s).As(Form).Icon= fx.LoadImage(File.DirAssets, "svr.png")
                B4XPages.MainPage.OpenForm.get(s).As(Form).Show
            End If
        Next
    Else
        B4XPages.MainPage.OpenForm.Put(c,Svcfrm) 'add form with client astream as key
        B4XPages.MainPage.OpenForm.get(c).As(Form).Initialize("form",600,400)
        B4XPages.MainPage.OpenForm.get(c).As(Form).RootPane.LoadLayout("ServicesLay")
        B4XPages.MainPage.OpenForm.get(c).As(Form).Title="Services Manager "
        B4XPages.MainPage.OpenForm.get(c).As(Form).Icon= fx.LoadImage(File.DirAssets, "svr.png")
        B4XPages.MainPage.OpenForm.get(c).As(Form).Show
    End If
    fillList(info) 'fill information
    checklistsize
   
End Sub

disconnect form code

B4X:
Public Sub formDisconnected (c As Client)
    For Each s As Client In B4XPages.MainPage.OpenForm.Keys
        If s = c Then
            B4XPages.MainPage.OpenForm.Get(s).As(Form).Close 'close form of disconnected client
            B4XPages.MainPage.OpenForm.Remove(s)  'remove from map
        End If
    Next
End Sub
 
Upvote 0
Top