1. Black Friday Sale - 50% off

    B4A Standard for $29 instead of $59!
    Buy Now
    Dismiss Notice

B4J Question [BANano] [SOLVED] Map.IsInitialized Inclusion on map keys

Discussion in 'B4J Questions' started by Mashiane, Jan 19, 2019.

  1. Mashiane

    Mashiane Expert Licensed User

    Hi there

    I was just cleaning my project and removed all .clear methods for my maps as I noted in the transpiled code that clearing them was not necessary due to to .initialize method just after 'dim m as map', thing is this has resulted in something else.

    This is what happens...

    When maps are defined with CreateMap, everything is well. The issue is when a map is dimmed, initialized and then put statements are used. Whilst CreateMap returns an undefined '.isinitialized' value for the map, dimming a map, then calling .initialize and then .put, results in a true '.isinitialized' value, which is also included as part of the map keys and values.

    Case 1

    Dim nm As Map = CreateMap("a""a""b""b""c""c")
    Log (nm.IsInitialized)
    This returns 'undefined' on the log for .isinitialized

    Case 2

    Dim nm As Map
    This returns 'true' on the log for .isinitialized, however '.isinitialized' is added to the map size and thus on .GetKeyAt and .GetValueAt as 'isinitialized' and 'true' respectively, i.e. part of the .Keys value


    Having .Clear just after .Initialize ensures that .isinitialize does not exist and is 'undefined' in Case 2, this is the solution in my case, but perhaps something to look at?

    Attached Files:

    joulongleu likes this.
  2. alwaysbusy

    alwaysbusy Expert Licensed User

    I will remove isinitalized from BANano. In javascript this has no meaning (it is always intialized) and I only added it for B4J compatibility but it appears to do more harm than good. Good catch!
    Don Oso and joulongleu like this.
  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