S sorex Expert Licensed User Longtime User Dec 12, 2014 #1 Hello, I'm trying out some class coding again and bumped into something I can't seem to solve and would like to have an explanation or solution on the behaviour. I had it working by "posting" the panel name to the init & subs of the class. But when trying to cut down the code a bit and using less sub calling variable I thought about sending the panel name in the init once and store it somewhere but I can't get it to work right. the minified code looks like this... Code: Sub Class_Globals Dim mainactivity As Activity Dim menupanel As Panel End Sub Sub Initialize(act As Activity,menu_panel As Panel) mainactivity=act menupanel=menu_panel End Sub Sub start() menupanel.Visible=False end sub I get errors that menupanel is not initialized. If I init it the error is gone but the panel is still visible, so I guess it created a new one and hides that?
Hello, I'm trying out some class coding again and bumped into something I can't seem to solve and would like to have an explanation or solution on the behaviour. I had it working by "posting" the panel name to the init & subs of the class. But when trying to cut down the code a bit and using less sub calling variable I thought about sending the panel name in the init once and store it somewhere but I can't get it to work right. the minified code looks like this... Code: Sub Class_Globals Dim mainactivity As Activity Dim menupanel As Panel End Sub Sub Initialize(act As Activity,menu_panel As Panel) mainactivity=act menupanel=menu_panel End Sub Sub start() menupanel.Visible=False end sub I get errors that menupanel is not initialized. If I init it the error is gone but the panel is still visible, so I guess it created a new one and hides that?
DonManfred Expert Licensed User Longtime User Dec 12, 2014 #2 You should initialize the panel before you initialize your class so the object you give as parameter should be initialized at this moment... Upvote 0
You should initialize the panel before you initialize your class so the object you give as parameter should be initialized at this moment...
S sorex Expert Licensed User Longtime User Dec 12, 2014 #3 thanks to TDS for the hint on Activity.LoadLayout() , it was placed under the class init's Upvote 0
S sorex Expert Licensed User Longtime User Dec 12, 2014 #4 Manfred: another issue... I use a call to another class Code: Sub startGame() Log("start game") Dim game As GameClass game.start() End Sub which gets executed to the point that I call the panel storage variable where I get a null pointer error while the panel storage variables are set in both classes during the init. Code: Sub start() Log("game started") menupanel.Visible=False <- null pointer happends here gamepanel.Visible=True End Sub Upvote 0
Manfred: another issue... I use a call to another class Code: Sub startGame() Log("start game") Dim game As GameClass game.start() End Sub which gets executed to the point that I call the panel storage variable where I get a null pointer error while the panel storage variables are set in both classes during the init. Code: Sub start() Log("game started") menupanel.Visible=False <- null pointer happends here gamepanel.Visible=True End Sub
S sorex Expert Licensed User Longtime User Dec 12, 2014 #5 ok, it seems that I start seeing how these classes are (supposed to) working with each other. I had to add a Code: game.Initialize(mainactivity,menupanel,gamepanel) right after the dim game, which makes sense (now) since you pass the values to a new class object. Upvote 0
ok, it seems that I start seeing how these classes are (supposed to) working with each other. I had to add a Code: game.Initialize(mainactivity,menupanel,gamepanel) right after the dim game, which makes sense (now) since you pass the values to a new class object.