problem with AHQuickAction3D

melamoud

Active Member
Licensed User
Longtime User
hi,

I need to make the var of type AHQuickAction3D public (global) since I need to get the values when someone click,

the items need to be dynamic (depend on a cell (from a table) the user clicked on

so bottom line I have a global object AHQuickAction3D and the first time I add ActionItems , but what do I do the second time ?
I do not have removeActionItems right ?

I do not have a way to distroy the AHQuickAction3D object and rebuild it ? (initialize does not do that)

any help willbe approciated !
 

corwin42

Expert
Licensed User
Longtime User
You can Dim the AHQuickAction3D object again everywhere in your code. This will create a completely new instance and you have to initialize it again. This new instance is accessible over the gloabal variable name. The old object will then be discarded by the garbage collector.

There is often confusion what Dim and x.Initialize do. Dim creates a complete new object so creates a new instance of the object. Initialize initializes an existing object (mostly setting Event Sub names etc.) and does not create a new instance.
 
Upvote 0

melamoud

Active Member
Licensed User
Longtime User
I deleted my post because I made a confusion between Java and B4A.
Dim myClsPanel As ClsPanel
generates in Java:
ClsPanel myClsPanel = new ClsPanel();

so I cant yse that trick right ? if dim create a new object it wont be accesable through the global pointer, I wont get access to the new one

am I missing something ?
 
Upvote 0

corwin42

Expert
Licensed User
Longtime User
Yes, you can use it as I said. If you dim a global variable again Dim will create a new instance of the global variable.

sent from my Galaxy Nexus
 
Upvote 0

melamoud

Active Member
Licensed User
Longtime User
Yes, you can use it as I said. If you dim a global variable again Dim will create a new instance of the global variable.

sent from my Galaxy Nexus

thank you, it is working,
care to explain why ?

it against my JAVA /C++ background :)
you define a global var by the name of X, and than you re-define it localy into a sub with the same name, yet the global var gets the local definition - ouch!


do you know how it translate to Java ?
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
Hi

I know this is an old thread, but I am getting an error after I dim the menu in a local function

B4X:
Sub Process_Globals

   Dim acChannels As AHQuickAction3D

end sub
Sub Activity_Create(FirstTime As Boolean)


   If FirstTime Then
     
     ' // menu's
     acChannels.Initialize("ac_channels", acChannels.VERTICAL)

   end if

end sub

Sub make_menus_acChannels

   Dim i As Int, s As String
   
   s = "SELECT ptt_users_channels.channel_id, ptt_channels.channel_name FROM ptt_users_channels " & _
     "INNER JOIN ptt_channels ON ptt_users_channels.channel_id=ptt_channels.channel_id ORDER BY ptt_users_channels.channel_id"
   ' // get list of cases for current view
   Dim rs As Cursor     
   rs = SQLDB.ExecQuery(s)
   show_channel_count
   If rs.RowCount = 0 Then
     Return
   End If
   
   ' // re-create the menu
   
   Dim acChannels As AHQuickAction3D
   
   
   For i = 0 To (rs.RowCount-1)
     rs.Position = i
     
     Dim ai As AHActionItem
     Dim bd As BitmapDrawable
     Dim Filename, Text As String
         
     Filename = "walkie_talkie_white_24pxi.png"
     Text = rs.GetInt("ptt_users_channels.channel_id") & "-" & rs.GetString("ptt_channels.channel_name")
     ' // Initialize a bitmap drawable and the action item
     bd.Initialize(LoadBitmap(File.DirAssets, Filename))
     ai.Initialize( rs.GetInt("ptt_users_channels.channel_id") , Text, bd)
     ai.Selected = True     
     acChannels.AddActionItem(ai) <- ERROR HERE Null pointer exception
     
   Next
   
   

End Sub

I too dynamically create the menu.

Regards

John
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Top