Android Question Step through "Type" variables?

Discussion in 'Android Questions' started by TheMightySwe, Mar 16, 2015.

  1. TheMightySwe

    TheMightySwe Active Member Licensed User

    Is there any way to step through a "Type" like the one below in some kind of loop?

    Code:
    Type SQLTypes (BlobType As Int, DateTimeType As Int, StringType As Int, DoubleType As Int, IntType As Int, BooleanType As Int)
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Do you want to go over all the fields? Create a sub that receives this type and returns a Map with the fields names as keys and the values.
     
    Peter Simpson likes this.
  3. TheMightySwe

    TheMightySwe Active Member Licensed User

    So how do I do that convertion from the type to the map?
     
  4. Troberg

    Troberg Well-Known Member Licensed User

    You'll have to do it manually, field by field.

    Bara kavla upp ärmarna, ladda med kaffe och köra igång... :)
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    Code:
    Sub SQLTypesToMap (t As SQLTypes) As Map
     
    Return CreateMap("Blobtype": t.Blobtype, "DateTimeType": t.DateTimeType, ...)
    End Sub
     
    Peter Simpson likes this.
  6. TheMightySwe

    TheMightySwe Active Member Licensed User

    OK, oh my!

    That might work, but with a huge problem.

    My Type has almost a thousand Integers and changes alot when new functions are added. Is there any way to step through it to get the Variable names?

    If not, i just do it the hard way.

    // TMS
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    Why do you need to go over all the fields? If you want to serialize the type instances then there are simpler ways to do it.
     
  8. TheMightySwe

    TheMightySwe Active Member Licensed User

    I want to use the Names from the type instances for a map that saves if a user has or hasn't access to the function that corresponds with the type instance.
     
  9. Troberg

    Troberg Well-Known Member Licensed User

    Maybe you should take a step back and reconsider using a type and think about using some other construct instead? Class, map, array, list, database are all viable alternatives, depending a bit on your specific needs.
     
    DonManfred likes this.
  10. Erel

    Erel Administrator Staff Member Licensed User

    Use KeyValueStore (or RandomAccessFile.WriteB4XObject). It allows you to save a type instance or any collection that holds other types in a single line of code.
     
  11. TheMightySwe

    TheMightySwe Active Member Licensed User

    The thing is i can't change this because its embedded in thousands of places in a huge project, if it's not possible to get the variables names out, I will fix another solution ofcourse. But it does not hurt to ask.
     
  12. Troberg

    Troberg Well-Known Member Licensed User

    I don't know the project, but, in my experience, don't underestimate the power of search and replace, and simple find and manual correct.

    I'd make a copy of the project, and then start doing the change, just to get a feel for how big it really is. Usually, when I fear a big rewrite, it's much less work than I thought.
     
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