include files vs code modules & classes

sorex

Expert
Licensed User
Longtime User
Hello,

I'm messing around with some code which I put in a sub routine.

Everything worked fine that way.

Now I was thinking ahead about larger projects and thought about reorganising my file a bit so that panel routines and other stuff were placed into their own modules seperated from my main code, just to be prepared so to say.

Here is where I ran into trouble...

I thought code modules were like the good old include files but apparently they aren't since we can't even "reach" the views from in a coding module?

another option is the class module, this required some rewriting until my source finally compiled. But when I run it I get an error that a listview is not initialised altho it's Dim'ed in the class globals.

So I'm wondering which solution I need here to get this subroutine working that just fills a listview with some data (and maybe can access a main variable)
 

klaus

Expert
Licensed User
Longtime User
You can have routines in a code module and transmit views as parameters in the calling routine.
' Main module
In your example:
B4X:
' Main module
CodeModule.FillListView(ListView1)
B4X:
'CodeModule
Sub FillListView(Ltv As ListView)
  Dim i As Int
  For i = 0 To 10
    ltv.Add("Test " & i)
  Next
End Sub
Best regards.
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
Thanks Klaus!

That was the key to success :)

The only bad part is if you have a positioning sub routine like below
but with a lot more items that you need to supply them all in the command.


B4X:
Sub showpanel2(e)
Panel2.visible=e
Panel2.Left=0
Panel2.Top=0
Panel2.Width=100%x
Panel2.Height=100%y
BtnReturn2player.Width=100%x
BtnReturn2player.Height=40dip
BtnReturn2player.Top=100%y-BtnReturn2player.height 
BtnReturn2player.Left=0
listview1.Top=0
listview1.Left=0
listview1.Width=100%x
listview1.Height=100%y-BtnReturn2player.height
End Sub
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
that's usefull indeed.

I didn't figure out yet how the resolution specific part exaclty works
but can I use that to load a different background image aswell?

My phone only has a 240x400 display so downscaled picture don't look always that good
you could prevent that by loading an image based on that resolution.
 
Upvote 0
Top