Results 1 to 4 of 4

Thread: [Answers] Library-1

  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.

  2. #2
    Lianja MVP
    Join Date
    Dec 2012
    Location
    Croatia, Zagreb
    Posts
    1,135
    Q:
    when I set an external library loaded with SET PROCEDURE TO, I lose access to the custom library functions or both are available?
    A:
    You will still have access to your App's custom library/libraries.
    You can use SET PROCEDURE TO <lib> ADDITIVE for multiple extra procedure/function libraries.
    The ADDITIVE means that it is opened in addition to any existing libraries.
    The LIST PROCEDURE command will list the procedures and functions that are currently defined.



    Q:
    I have a page, "Leave_balance" in my app
    I opened my app and goto "Console" workspace
    When I issue the command, "Lianja.ShowDialog("Some title","Leave_Balance"), the system display only a blank popup window instead of my page in the popup window.
    A:
    Lianja.showDialog() displays pages from the UI page library not the current app.
    Save the page in the UI a Page library to be able to use it like that.




    All topics in [Answers] alphabetically: http://www.lianja.com/community/show...p?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 05:57.

  3. #3
    Lianja MVP
    Join Date
    Dec 2012
    Location
    Croatia, Zagreb
    Posts
    1,135
    Q:
    If I have a .prg in my app and I right-click & select 'Add to Library' then the prg gets copied into the library section and I can use it as a library file, all ok.
    The original file stays behind with the 'app files' though and it appears that there is no link between the newly created 'library file' and the original one because changes are not persisted between them - is this just done for safety? I guess after adding a file to the library I would probably want to delete the original one from the app right?
    A:
    In an App, when you 'Add to library' (prg script file), the prg is copied to the library and can be used by other Apps. There is no link between the original App prg and the library copy. Changes to the library copy should be made in the Library workspace. If you want to use the library copy from your originating App, then yes, delete the App prg.
    If you have files called 'myprg.prg' in both your App and the Library and issue 'do myprg', the one in the App will be run. If you issue 'do myotherprg' and no myotherprg.prg exists in the current App, then the Library will be checked and the file run if it exists.



    with the library page in the library, the code called by the library page has to be in the library, and the delegates referenced in the page attributes have to have the lib:/ prefix on them



    Q:
    from a page, I open a saved page in the "Page Library" with the command: Lianja.showDialog (....), or showDialogPanel, is the same.
    If I try to debug, I do not see the code executed ..
    will it be possible to debug pages viewed with lianja.showDialog ()?
    A:
    what I've found is that if the debugger misses where I put the breakpoint, I start in the program that calls the one I'm interested in, and then step into it.
    A2:
    In the past when I have had to debug a page that gets called from showdialog, I debugged it from the original project.
    Meaning - lets say I had a project called leftpage. I then used that in another project called mainpage.
    When I opened mainpage, I could not debug leftpage.
    So I opened the project called lefpage and debugged the code in the original project where the code was created.



    All topics in [Answers] alphabetically: http://www.lianja.com/community/show...p?2717-Answers
    This same topic is extended to another thread: http://www.lianja.com/community/show...wers-Library-2

  4. #4
    Lianja MVP
    Join Date
    Dec 2012
    Location
    Croatia, Zagreb
    Posts
    1,135
    Q:
    I have a file in the library called convert2.dbo
    I am trying to call the file like so:
    Code:
    c:\lianja\bin\lianjaruntime.exe lib:/convert2dbo.dbo  --args "'TEST5_1_000001.jpg','TEST5_1_025001.jpg',50,'R:\test5\test5_ROLL2',2,'test5'"
    I have also tried
    Code:
    lib:\
    But not luck.
    When I change it back to a file in the application it runs fine.

    A:
    Lianjaruntime.exe has no idea, on its own, where lib: is. Even if you are calling it with a run or spawn from inside Lianja. It's in its own process.
    You can specify --runtimedir to tell it where these files dirs are: this would (perhaps: I have a memory of it not doing so) make the LIB files automatically available.
    You can specify --dir to set the default directory (the equivalent of having selected an app).
    I have code that predates these switches where I use left(sys(16),3) in the .dbo I'm calling to get the current drive and then figure everything out from there. Only works in Windows. I should change it to set("dire") which is also in Lianja now. That would make it OS independent. That particular SET("directory") command never got documented in VFP, although it was brought to their attention. It was very handy in VFP and is even handier here.




    All topics in [Answers] alphabetically: http://www.lianja.com/community/show...ll=1#post12352

    These answers are also systematized on the site "Lianja developer": https://lianjadeveloper.wordpress.com/category/library/

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