Other Views declared in Process_Globals

LucaMs

Expert
Licensed User
Longtime User
Is this a question? Yes but mainly it is a... "discovery"/info.


You can not declare a View in Process_Globals (the message you get is:
upload_2018-12-14_2-13-3.png


but... you can declare there a Type containing Views and use an object of that type in your Activity.

Tested so:
B4X:
Sub Process_Globals
   Type tViews(CV As cvFake) ' cvFake is a Custom View with just the default stuff.
End Sub

Sub Globals
   Private cvFake1 As cvFake
   Private marr(1) As tViews
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("layMain")
   marr(0).CV = cvFake1
   Sleep(1000)
   marr(0).CV.GetBase.Color = Colors.Blue
End Sub

This code works without problems.




P.S. It works even with "simple" views (which is my purpose; the first example makes no sense in that way, of course):
B4X:
Sub Process_Globals
   Type tViews(CV As cvFake, lbl As Label)
End Sub

Sub Globals
   Private cvFake1 As cvFake
   Private marr(1) As tViews
   Private Label1 As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("layMain")
   marr(0).CV = cvFake1
   marr(0).lbl = Label1
   Sleep(1000)
   marr(0).CV.GetBase.Color = Colors.Blue
   marr(0).lbl.Text = "ciao"
End Sub
 
Last edited:

Computersmith64

Well-Known Member
Licensed User
Longtime User
So I'm wondering:

a) What the practical uses of this are @LucaMs?
b) Are you inferring (@Erel) that this will create a runtime issue?

- Colin.
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
In my case... I have a CV representing a player, with its views; but other views are logically connected to it, then I create a type like that.

OK - but what is the benefit of declaring it as a Process Global instead of a Global? Are you intending to reference it from another Activity or Class?

- Colin.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
OK - but what is the benefit of declaring it as a Process Global instead of a Global? Are you intending to reference it from another Activity or Class?

- Colin.
It was just a surprise to me that I was able to declare that "kind" of type in Process_Globals. I was pasting code from a b4j test project to b4a and I... discovered this fact. Obviously I have no reason to declare that type there. It's just a... "curiosity".
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
It doesn't matter where you declare the custom type.
I'm not sure if you're replying to me or not, but I'm trying to figure out what the benefit of declaring a custom type in Process Globals is.

To me, it seems that if you have a type containing various variables & one or more views, you'd probably be better off creating a class. But I could be wrong...

- Colin.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I'm not sure if you're replying to me or not, but I'm trying to figure out what the benefit of declaring a custom type in Process Globals is.
Yes, I replied to you. It doesn't matter where you declare the type. It only matters where you 'dim' a variable of that type.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
a) What the practical uses of this are @LucaMs?
In my case... I have a CV representing a player, with its views; but other views are logically connected to it, then I create a type like that.
I have something like this:

upload_2018-12-14_8-54-9.png


So I can not insert the circle (and other views "logically connected" to a CV) inside the CV, because it is "far" (other views may be partially overlap the CV to which anyway they are "connected").

Then I think to create a "Player GUI" type (a sort of large CV - without methods, properties and events, of course, but useful):

Type tPlayerViews(CV As cvPlayer, Circle As ImageView, OverlappingView As ImageView, ...)
 
Last edited:
Upvote 0
Top