Results 1 to 4 of 4

Thread: [Answers] Library-1

Threaded View

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

    [Answers] Library-1

    If you only need the file to be available to a particular app then open that app and add the file via the Apps Workspace. If you want it available to multiple apps then put it in the Lianja Library (via the Library Workspace).



    If it is a standalone prg, just click the + button at the bottom of the 'Files' in the Sidebar in the Apps Workspace and it will prompt you for the filename. The default file extension is '.prg'. Yes, it will be available for the whole App. When you Deploy, it will be deployed as a .dbo (pseudo-compiled) file.
    If you have lots of functions you want to use, you can put them in a function/procedure library (create this using the + button as before):
    Then use set procedure to <lib> additive in a delegate called before the function is required, for example in the app.load() or the app.ready() (or a delegate for the relevant Page or Section).
    you can add functions ('anotherfuncstill' here) in with the event delegates. The custom libraries for event delegates (created when you create your first delegate) are opened for you automatically; there is no need to use set procedure in this case.
    Pages and Sections can also have a 'Valid When' event delegate called after the field validation.



    It's handling the SET PROCEDURE correctly if the procedure library is in the App itself - it correctly loads the dbo. If the procedure library is in the Library, it is still expecting to find the prg.
    If you copy the prg files into the deployed library, or the dbo files into the deployed App, this will work around it until it gets fixed.



    Q:
    procedure in a seperate prg file. And perhaps that needs something like 'SET PROCEDURE TO' to work? My main page and most other stuff uses javascript / python as the scripting language. And I also wonder if the 'scope' of the procedure was something I missed, or didn't declare correctly ",)
    A:
    Yes, if it's a procedure in a procedure library you need a

    Code:
    set procedure to <prgfile> additive
    unless it is defined as the 'Custom Library' for the App, a Page or a Section, in which case that will be issued for you automatically.



    Q:
    How can I use a variable within several procedures in the same prg file?
    A:
    Remember that the section or page custom library where you define your event delegate procedures is a library, not a program that you are running from start to finish. The library declares your procedures, it doesn't call them, so it's not the same as one program/procedure calling another with the called procedure having access to the calling procedure's private variables, e.g. a private variable set in Gamesheet_GSHeader_field82_click would be accessible to set_value as it is called by Gamesheet_GSHeader_field82_click.
    To make a variable accessible to the procedures within your library, you do need to make it public. As Dave says, you could use a namespace to avoid conflicts. As I mentioned in a previous post, you can access public variables declared in a namespace with namespace.variable. You can also access them with just the variable name if your procedure is in the same namespace. For example:

    Code:
    // lib_Gamesheet_gsheader.prg
    namespace gsheaderpublic testmsg = "Blank"
    
    proc set_value()
            namespace gsheader
            testmsg = "testing"
            messagebox("Set Value message " + testmsg)
            messagebox(priv1) // private variable in calling procedure
    endproc
    
    ////////////////////////////////////////////////////////////////
    // Event delegate for 'click' event
    proc Gamesheet_GSHeader_field82_click()
            namespace gsheader  // not currently required as does not use namespace public vars
            private priv1 = "Hello" // accessible to set_value
            set_value()
    endproc
    
    
    ////////////////////////////////////////////////////////////////
    // Event delegate for 'click' event
    proc Gamesheet_GSHeader_field83_click()
            namespace gsheader
            messagebox(testmsg) 
    endproc
    I could then have the same variable name in another page in another namespace, e.g.

    Code:
    //lib_page1_section1.prg
    namespace section1public testmsg = "This is section 1"
    
    ////////////////////////////////////////////////////////////////
    // Event delegate for 'click' event
    proc page1_section1_field78_click()
            namespace section1
            messagebox(testmsg)
    endproc




    I just meant design or at least complete the design with the UI Page in another App, so that you don't have 2 copies of the same Page and controls in the main App as (from experience that can be confusing. Once the Page is saved to the Page Library (yes, click the icon as Herb says to save it manually) it will be called from the Page Library, it just needs to be in an App too if you want to modify it. Herb's other instructions are for code called by the UI Page. The code can either reside in the main App or in the Library. If you want it in the Library, add the 'lib:/' prefix as Herb says and add the relevant prg scripts to the Library.



    Q:
    How to call one the same page from two different applications? Calling completely including a left bar, right bar. Of course I can copy the page, but this is not correct because of maintenance at 2 locations.
    A:
    You can include the Left and Right Sidebars in a Page saved to the Page Library, they just need to be set to be shown in the Page Attributes



    Q:
    how I can have multiple functions in one file.
    A:
    Put your app specific functions in the custom library file for the app. Put your page specific functions in the custom library for the page. Same goes for section specific functions.



    While you are developing and testing that is the case. The class libraries will not be automatically reloaded if the source file is edited.
    In the App Builder itself, it listens for any custom libraries or other relevant files being edited and automatically recompiles and reloads them.
    This in fact is how a lot of the "live" development is accomplished.



    Try using SET CLASSLIB rather than SET PROCEDURE and omit the file extension.
    Although set procedure will handle class definitions it is better to use set classlib.

    Code:
    set classlib to formclasses
    list classlib
    list classes
    will show you what classes are in scope.


    Code:
    set procedure to mylibrary
    list procedure
    will show you what procedures and functions are in scope.
    useful functions to be aware of:


    Code:
    ? function_exists("myprocname")
    ? class_exists("myclassname")
    So in your code:


    Code:
    proc openLibs()
        if not function_exists("myfunc")
            set procedure to myfunclib additive
        endif
        if not class_exists("basebutton1")
           set classlib to formclasslib additive
        endif
        // etc...
    endproc
    Code:
    require_once("formclasslib.vcp")
    Which takes care of a lot of messing about with determining if a class library has been loaded or not. The classes are however declared at the current scope level and will be released when the proc returns.
    If you are using these classes in a modal form then they will remain in scope until the form is closed. e.g.

    Code:
    // myform.prg
    require_once("alan.scp")
    loForm = createobject("myform")
    loForm.show(1)    // blocks execution until the form is closed.
    Once you have satisfied yourself that your UI forms and classes are working, you can embed them in a "Custom" section. See below.






    All topics in [Answers] alphabetically: http://www.lianja.com/community/showthread.php?2717-Answers
    This same topic is extended to another thread: http://www.lianja.com/community/show...wers-Library-2
    Last edited by josipradnik; 2016-12-02 at 06:08.

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