Other Views declared in Process_Globals

Discussion in 'Android Questions' started by LucaMs, Dec 14, 2018.

  1. LucaMs

    LucaMs Expert Licensed 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:
    Code:
    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(1As 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):
    Code:
    Sub Process_Globals
       
    Type tViews(CV As cvFake, lbl As Label)
    End Sub

    Sub Globals
       
    Private cvFake1 As cvFake
       
    Private marr(1As 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: Dec 14, 2018
  2. Erel

    Erel Administrator Staff Member Licensed User

    Don't confuse the declaration of a type with an instance of that type. The declaration itself doesn't create any object.
     
  3. Computersmith64

    Computersmith64 Well-Known Member Licensed 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.
     
  4. LucaMs

    LucaMs Expert Licensed User

    I know... as you know (maybe) :)
     
  5. LucaMs

    LucaMs Expert Licensed 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.

    No; as you can see that code works without problems.
     
  6. Computersmith64

    Computersmith64 Well-Known Member Licensed 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.
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    It doesn't matter where you declare the custom type.
     
  8. LucaMs

    LucaMs Expert Licensed User

    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".
     
    Computersmith64 likes this.
  9. Computersmith64

    Computersmith64 Well-Known Member Licensed 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.

    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.
     
    LucaMs likes this.
  10. LucaMs

    LucaMs Expert Licensed User

    I also always prefer classes to types; in this case, however, it is only GUI stuff.
     
    Computersmith64 likes this.
  11. Erel

    Erel Administrator Staff Member Licensed User

    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.
     
    Computersmith64 likes this.
  12. LucaMs

    LucaMs Expert Licensed User

    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: Dec 14, 2018
    Computersmith64 likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice