Page 1 of 4 123 ... LastLast
Results 1 to 10 of 31

Thread: Global object

  1. #1
    Senior Member
    Join Date
    Apr 2012
    Location
    United Kingdom
    Posts
    657

    Global object

    In my current VFP application I have a table dPref which holds the users preferences for the application.

    Very early on in the app I call a prg which creates on object oPref attached to _screen,oApp and then issue

    SCATTER NAME _SCREEN.oApp.oPref MEMO.

    I could just be using SCATTER NAME _SCREEN.oPref MEMO rather than adding it to the oApp object.

    Then though-out my app when I want to get the value of one of the preferences I can simply refer to the object, rather then have to make a call to a prg to use a select statement to get it.

    for example:
    LOCAL lnDays
    lnDays = 0

    IF _SCREEN.oapp.opref.nUpdateDays > 0
    IF _SCREEN.oapp.opref.tLastUpdate < DATETIME()
    lnDays = aim_calculate_days_between_datetimes(DATETIME(), _SCREEN.oapp.opref.tLastUpdate)
    IF lnDays > _SCREEN.oapp.opref.nUpdateDays
    IF YesNo_Msg('Check for updates')
    aim_version_check()
    aim_update_autocheck_date()
    ENDIF
    ENDIF
    ENDIF
    ENDIF

    What would be the best way to do this in Lianja in:

    1. Desktop apps

    2. Web apps

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

    In desktop you can use the same as you have however you can only SCATTER to a name. So you need to do something like this.

    _screen.oApp = object()
    Scatter name opref
    _screen.oApp.oPref = opref

    Use Lianja.public in web apps. It’s an object you can add objects/variables to.

    although personally I would use Lianja.localstorage for both desktop and web.
    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. #3
    Senior Member
    Join Date
    Apr 2012
    Location
    United Kingdom
    Posts
    657
    Thanks Barry,

    In my current vfp app when the users goes into the preferences form and makes a change the code once the save has gone though redoes the object.

    So In Lianaja can one do

    Scatter name _screen.oApp.opref
    if opref alraeasy has values?

    Or similarly at the very start coukdl I issue

    _screen.oApp = object()
    _screen.oApp.oPref = object()

    Scatter name _screen.oApp.oPref


    I would dispense with the oApp reference in Lianja as it would make no sense, although I'l have to go through my existing code once it was moved over and alter the references to it, so perhaps I'l leave it as it was to save work initially.

    I'll take a look at local storage.

    David

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

    not exactly.

    Scatter name oPref
    _screen.oApp.oPref = opref
    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. #5
    Senior Member
    Join Date
    Apr 2012
    Location
    United Kingdom
    Posts
    657
    Thank you

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

    I have done a search in the document wiki for local storage, but it does not seem to be there.


    Also tried Lianja.localstorage, same result
    David

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

    https://www.lianja.com/doc/index.php/Lianja

    See localstorage on that page
    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

  8. #8
    Lianja MVP
    Join Date
    Feb 2012
    Location
    Berea, KY, USA
    Posts
    2,161
    Hi Barry & David,

    Barry's way of adding the record object to a property of the oApop object is exactly the same as VFP, FWIW.

    Hank

  9. #9
    Senior Member
    Join Date
    Apr 2012
    Location
    United Kingdom
    Posts
    657
    Hi Hank,

    I'd looked at the docs and could see that this was the same as we do it now in VFP.

    I was just concerned that it would not work in Web and mobile.

    I've looked at the local storage option and will play with that, but it would mean altering a lot of code so I might go with the add object method for now to get more testing underway.

    If I can use something like set the values in the local storage in the same code as I now do the scatter to code, which is easy to do, then something like

    if nDays > Lianja.localStorage.GetItem(nUpdateDays)

    I assume the data type in the localstorage are the same as the value set in them and not strings.

    Barry what do you see as the advantage of the localstorage approach rather than setting the object with a scatter?

    The more I play with all of this the more I see the absolute power in it, awesome.

    Once I get my Xcase2Lianja code working fully then I can really started building serious stuff for conversion of my existing bird system.

    David
    Last edited by avianmanagement; 2022-03-20 at 12:41.

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

    You should put oApp in localstorage and reference it’s members. From the console.

    Lianja.localstorage.setItem(“oApp”, oApp)
    ? Lianja.localstorage.getItem(‘oApp’j
    oApp.ndays = 10
    ? Lianja.localstorage.getItem(‘oApp’).ndays

    _screen is a desktop thing that’s why I suggested using localstorage if you want the code to work in web/javascript OTOH you could just as easily create _screen as an object in javascript

    _screen = {}
    _screen.oApp = {}
    _screen.oApp.ndays = 10

    Hiwever, in web apps reading preferences from the server and storing in an localstorage object aims.oprefs seems better to me.



    .
    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

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