Page 2 of 4 FirstFirst 1234 LastLast
Results 11 to 20 of 31

Thread: Global object

  1. #11
    Senior Member
    Join Date
    Apr 2012
    Location
    United Kingdom
    Posts
    657
    Thanks Barry,

    The local storage looks a very good way to do it using

    lnDays = Lianja.localstorage.getItem(‘oApp’).ndays

    I can easily do a search and replace in my code using that for my existing calls

    That way I just need to have one code to make the objects in all platforms.

    Many thanks

    David

  2. #12
    Lianja Development Team barrymavin's Avatar
    Join Date
    Feb 2012
    Location
    UK, USA, Thailand
    Posts
    6,889
    Blog Entries
    18
    Hi David

    To avoid polluting localstorage on web i recommend you have an "aims" object that contains everything else.
    Principal developer of Lianja, Recital and other products

    Follow me on:

    Twitter: http://twitter.com/lianjaInc
    Facebook: http://www.facebook.com/LianjaInc
    LinkedIn: http://www.linkedin.com/in/barrymavin

  3. #13
    Senior Member
    Join Date
    Apr 2012
    Location
    United Kingdom
    Posts
    657
    Thanks Barry,

    So to create that I first create the aims object then add opref to it then use setitem('aims.opref',aims.opref)

    In the above if I later create aims.oegg is that treated as a separate object, added to the existing aims object in local storage or overwrites it?

    Or should I create an object aims then setitem('aims',aims) then reference that to add oPref to it?


    The oPref object is used for setting for code. Things like oEgg are passed as parameters to code, so they I assuem can just be created as object at the time and passed around rather than using local storage for them?
    Last edited by avianmanagement; 2022-03-21 at 00:44.

  4. #14
    Lianja Development Team barrymavin's Avatar
    Join Date
    Feb 2012
    Location
    UK, USA, Thailand
    Posts
    6,889
    Blog Entries
    18
    Hi David,

    Or should I create an object aims then setitem('aims',aims) then reference that to add oPref to it? Yes.

    aims = object()
    Lianja.localstorage.setItem("aims", aims)

    as "aims" is an object it can be assigned anywhere and its contents are shared. Am object
    reference in fact.

    aims.oApp = object()
    aims.oApp.oPrefs = object()

    etc.
    Principal developer of Lianja, Recital and other products

    Follow me on:

    Twitter: http://twitter.com/lianjaInc
    Facebook: http://www.facebook.com/LianjaInc
    LinkedIn: http://www.linkedin.com/in/barrymavin

  5. #15
    Senior Member
    Join Date
    Apr 2012
    Location
    United Kingdom
    Posts
    657
    Hi Barry

    if !used(dpref)
    use dpref in 0
    endif
    clear

    select dpref
    Scatter name oPref

    ? oPref.NUPDATEDAYS && works and prints 14 as expected
    Lianja.localstorage.setItem('oPref',oPref)
    * ? Lianja.localstorage.getItem(‘oPref’)

    ? Lianja.localstorage.getItem('oPref').NUPDATEDAYS

    Lianja.localstorage.setItem('oPref.NUPDATEDAYS',2)

    ? Lianja.localstorage.getItem('oPref').NUPDATEDAYS

    I would have expected this to print 14 then 2, it prints 14 once

    Can you please tell what I'm doing wrong.

    David
    Last edited by avianmanagement; 2022-03-21 at 02:30.

  6. #16
    Lianja Development Team barrymavin's Avatar
    Join Date
    Feb 2012
    Location
    UK, USA, Thailand
    Posts
    6,889
    Blog Entries
    18
    Lianja.localstorage.setItem('oPref.NUPDATEDAYS',2) is meaningless

    The item is a member name not an
    arbitrary expression.

    Principal developer of Lianja, Recital and other products

    Follow me on:

    Twitter: http://twitter.com/lianjaInc
    Facebook: http://www.facebook.com/LianjaInc
    LinkedIn: http://www.linkedin.com/in/barrymavin

  7. #17
    Senior Member
    Join Date
    Apr 2012
    Location
    United Kingdom
    Posts
    657
    Hi Barry,

    This does not print anything to the console

    *Lianja.localstorage.removeitem('oPref')

    select * from dpref into cursor temp1
    select temp1
    Scatter name oPref

    * ? oPref.NUPDATEDAYS && works and prints 14 as expected

    Lianja.localstorage.setItem('oPref',oPref)
    ? Lianja.localstorage.getItem('oPref').NUPDATEDAYS

    Nothing printed

  8. #18
    Senior Member
    Join Date
    Apr 2012
    Location
    United Kingdom
    Posts
    657
    Quote Originally Posted by barrymavin View Post
    Lianja.localstorage.setItem('oPref.NUPDATEDAYS',2) is meaningless

    The item is a member name not an
    arbitrary expression.

    So how does one alter the value of oPref.NUPDATEDAYS in the local storage?


    Lianja.localstorage.getItem('oPref').NUPDATEDAYS = 2 ?
    Last edited by avianmanagement; 2022-03-21 at 02:30.

  9. #19
    Lianja Development Team barrymavin's Avatar
    Join Date
    Feb 2012
    Location
    UK, USA, Thailand
    Posts
    6,889
    Blog Entries
    18
    Yes
    Principal developer of Lianja, Recital and other products

    Follow me on:

    Twitter: http://twitter.com/lianjaInc
    Facebook: http://www.facebook.com/LianjaInc
    LinkedIn: http://www.linkedin.com/in/barrymavin

  10. #20
    Senior Member
    Join Date
    Apr 2012
    Location
    United Kingdom
    Posts
    657
    Thanks Barry,

    I'll get the hang of this one day

    ? Lianja.localstorage.getItem('oPref').NUPDATEDAYS

    I get no output to the console on this

    where as the OPref object before it's added using the setitem does have a value for NUPDATEDAYS

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Journey into the Cloud
Join us