Results 1 to 1 of 1

Thread: [Answers] Library-2

  1. #1
    Lianja MVP
    Join Date
    Dec 2012
    Location
    Croatia, Zagreb
    Posts
    1,135

    [Answers] Library-2

    Custom libraries are loaded internally and are not affected by SET PROCEDURE TO in any way at all.
    This is another reason why I recommend their use.



    No I'm referring to the custom library for the App itself.
    Go into App settings.
    Scroll down the attributes to the delegates.
    There is a custom library that gets automatically created if you create an init, load, ready, unload, inactive delegate.
    Editing that custom library lets you add your own functions.
    There is a custom library for each App, Page and Section. That's where the delegates live.
    Custom libraries are automatically opened when the App is loaded. They are monitored for changes for you and recompiled and reloaded. This is a fundamental part of the Lianja App Builder development cycle. There is no explicit compile or build required.
    This is the same principle for all of the supported scripting languages; Lianja/VFP, JavaScript, PHP or Python.



    My recommendation would be to place these functions in the App custom library rather than an external library loaded with SET PROCEDURE TO.
    Why? Because lianja knows when any of these files have been edited and automatically recompiles and reloads them. That is not the case with SET PROCEDURE TO. This is exactly what happens when you edit your delegates, custom section code or ,rsp files that generate dynamic WebView content too. There is no compile and build steps required. It is done for you as the whole App is live. The UI knows when files have changed.
    Also an advantage to this approach is that it is scripting language independent.
    Note also that if you must use SET PROCEDURE TO you can check to see whether the library is already loaded by looking for a "well known function" in the library e.g.

    Code:
    if not function_exists("__mylib__")
        Set procedure to mylib additive
        // inside mylib.prg declare an empty function called __mylib__
    Endif
    // alternatively use require_once() which does all the hard work for you

    Code:
    require_once("mylib")


    Q:
    I realise that sometimes, my changes will not take effect if I run the app immediately after making the changes
    I need to load another app and reload back my original app.
    May I know if there is a better way to force a refresh so that when I run the app, it will take the latest source files?
    A:
    If you are using custom libraries these will automatically be recompiled and reloaded if they are edited.
    If you have libraries that you are using that Lianja knows nothing about then you will need to save and reload your application for these to take effect.



    In Lianja "Procedure libraries" can contain:
    - classes
    - procedures
    - functions
    Procedures and Functions are essentially the same thing. It's good practice to use "Function" if it returns a result and "Procedure" if it does not. It's all down to personal taste.
    Script files (.prg) are opened and closed every time you call them. Not a good idea for your own functions. The file should just contain the code.

    Code:
    //myfunc.prg
    return "Hello world"
    //mylib.prg
    function myfunc()
    return "Hello world"


    Q:
    I have no problem defining multiple functions in libraries but I cannot see how to call these directly from attributes (without having an intermediate prg file as per my first post)
    A:
    Just edit a custom library, add your function and specify it in an expression:
    Code:
    myfunc()
    and in a custom library:
    Code:
    function myfunc()
    // your code
    endfunc
    Custom libraries are always opened when your app is opened.
    When you edit a custom library Lianja detects that it has changed and will reload it automatically and compile it.



    All topics in [Answers] alphabetically: http://www.lianja.com/community/show...ll=1#post12352
    This same topic is extended to another thread: http://www.lianja.com/community/show...wers-Library-1
    Last edited by josipradnik; 2016-12-02 at 06:13.

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