Results 1 to 4 of 4

Thread: [Answers] Referencing

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

    [Answers] Referencing

    Q:
    Using the tried and true Lianja.get("page.section.field") works fine until I try it in a web page. Looking at example_webapp3, the fields are simply referenced directly by their name. No page, no section, just name.
    A:
    This applies to the Canvas controls. If you wanted to reference a formitem in the 'Customer' Form Section in example_webapp3, you would use the Lianja.get() syntax
    You reference the fields directly by variable name in both desktop and web for javascript canvas sections.

    Q:
    Code:
    ?empty(Lianja.Get("page.section.txt1").text) .and. empty(Lianja.Get("page.section.txt2").text)
    "Syntax error in expression"
    A:
    Code:
    ? (empty(Lianja.Get("page.section.txt1").text)) and (empty(Lianja.Get("page.section.txt2").text))


    Q:
    why in some cases, calling a method or property directly works (which is what I was trying to do), while other times, such as this one, it is required to place something into a variable and then call different properties/methods with the variable.
    A:
    You can also do:
    Code:
    ? Lianja.GetElementByID("page.section").grid.ColumnCount
    or
    Code:
    ? Lianja.get("page.section").grid.column(2).header1.caption
    But, you do have to call the property/method on the relevant object where these are compound objects. A grid section is a grid within a section and is composed of columns, each of which has a header.




    Q:
    Grid
    Code:
    ?Lianja.GetElementByID("page.section").ColumnCount
    A:
    Get the grid object reference from the section:

    Code:
    oGrid = Lianja.GetElementByID("page.section").grid
    ? oGrid.ColumnCount


    In Standard and Canvas sections you can use the hierarchy, (Lianja.getObject("page1.section1") etc.) but in the Recital/VFP Custom Sections and Gadgets, you need to declare a public reference to the object if you want to access it outside of its creation procedure. This can be in a namespace, as in my example below (a namespace statement for the App is added automatically), which means I could have another optgrp in another namespace and still reference this one using herb1.optgrp.



    When you use the Lianja.getElementByID, you can either use the control name on its own if it is unique, e.g.
    Code:
    Lianja.getElementByID("Gkz").additem(<item>)
    or with the object hierarchy, e.g.
    Code:
    Lianja.getElementByID("Inventurauswahl.NameOfCanvasSection.Gkz").additem(<item>)
    If you are using a single database throughout the App, then put the open database cipinventur in the App (Settings) Init Event Delegate. You can SELECT the data into an array or cursor.



    In v1.3 the following attributes have been added.
    In a formitem:
    sectionid
    pageid
    In a section:
    pageid



    In your code you are updating the field on the form by assigning it a value in the dialog button delegate.
    When assigning a textual value like that you need to update the bound data source in your case the field in the table.
    Only interactive changes to the fields will update the bound data source not programmatically doing it in a delegate.
    Also remember that if you update the data source e.g. a field in a record or a variable then you refresh the formitem it will reflect the current value.



    Note that Lianja.get() does not require "page:", you are looking up the object.
    Lianja.showDocument() has many different commands so you need to specify "page:"



    Q:
    Using the tried and true Lianja.get("page.section.field") works fine until I try it in a web page.
    Looking at example_webapp3, the fields are simply referenced directly by their name. No page, no section, just name.
    For example, this is used to clear the fields when a button is clicked.


    Code:
    function page1_section2_field23_click()
    {
            m_companyname.text = "";
            m_companyregion.text = "";
    }

    I was certain that this was working before.
    Code:
    Lianja.get("page.section.field")
    A:
    Yes you reference the fields directly by variable name in both desktop and web for javascript canvas sections.
    Note, that this applies to the Canvas controls. If you wanted to reference a formitem in the 'Customer' Form Section in example_webapp3, you would use the Lianja.get() syntax, e.g.


    Code:
    ////////////////////////////////////////////////////////////////
    // Event delegate for 'click' event
    function page1_section2_field23_click()
    {
            m_companyname.text = "";
            m_companyregion.text = "";
            messagebox(Lianja.get('page1.section1.field1').text);
    }


    Q:
    Code:
    Lianja.showDocument("Page:pgAppendVoterData")
    or
    Code:
    Lianja.showDocument("page:pgAppendVoterData")
    A:
    page: is case sensitive as are all the actions.





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










  2. #2
    Lianja MVP
    Join Date
    Dec 2012
    Location
    Croatia, Zagreb
    Posts
    1,135
    Q:
    I'm having an issue when an option button is selected (option group click event) and it tries to determine if certain options are enabled or disabled.

    Code:
    if Lianja.Get("actions.secPhoneMenu.ogPhone").buttons(1).enabled = .T.


    A:
    Reference the button first, e.g.

    Code:
    oButton = Lianja.Get("actions.secPhoneMenu.ogPhone").buttons(1)
    if oButton.enabled
    ...



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

  3. #3
    Lianja MVP
    Join Date
    Dec 2012
    Location
    Croatia, Zagreb
    Posts
    1,135
    Q:
    With a dynamic array, is there a built-in function to check whether a specified element exists?
    A:
    PEMSTATUS()
    Also, the GETMEMBER() function returns the value of a dynamic array element or an alternative value if the element does not exist.



    The Lianja.getElementByID(item) method and its (quicker to type) synonym Lianja.get(item) allow you to call methods and get and set properties of the visual elements in the Lianja Object Model (LOM) hierarchy, from App through Pages and Sections to Formitems, Gadgets and Columns.



    Q:
    Are these two the same? I have had some strange results using the first syntax

    Code:
    loPge = Lianja.get("page1")
    loSec = loPge.section1
    and

    Code:
    loSec = Lianja.get("page1.section1")
    this works:

    Code:
    loSec = Lianja.get("Purchase_Orders.section1")  
    loSec.add()
    but this doesn't:

    Code:
    loPge = Lianja.get("Purchase_Orders")   
    loSec = loPge.section1
    loSec.add()
    A:
    The normal approach to referencing UI elements is to use Lianja.get() with dotted notation for page.section.formitem.
    You get an object reference then set its attributes and call it's methods in the way I previously described. This is scripting language independent.



    Q:
    I'm using canvases a lot in my app for the added flexibility they bring. In a desktop app, you can access (for example) the text in field1 of a canvas with

    Code:
    var myvar = Lianja.get("page1.section1.field1").text
    In non-desktop apps this seems to fail. I've tried running that both client- and server-side to the same result. Running in the JavaScript console in the web app debugger

    Code:
    Lianja.get("page1.section1.field1").text
    returns "".

    This makes me think the feature isn't implemented in non-desktop apps? If not, is there a different way of doing it? I find this functionality really useful in a lot of ways, for example setting the default value of a textbox dynamically based on what the user entered on a previous page.
    A:
    In JavaScript web and mobile apps they have a JavaScript object variable declared automatically as the ID of the UI control so naming is important.

    in your case here you would name field2 something sensible and just reference the properties as field2.property.

    Also look at the toJSON() method on sections if you want to gather all data off a form to send to a server side procedure for processing. Use this in conjunction with base64_encode() and base64_decode() on the server.



    Q:
    Code:
    cat = Lianja.get('Advanced_Search.section1').field13
    val_cat = cat.text
    
    cat.text
    Variable was expected!
    A:
    That is invalid syntax.You should use.
    Code:
    cat = Lianja.get('Advanced_Search.section1.field13')


    Lianja v2.1 includes two new methods on Pages, Sections and FormItems (fields and gadgets).

    These are setAttribute(name, value) and getAttribute(). These methods handle all attributes as documented and described in the MetaType Editor.

    e.g.

    Use Lianja.get("page1").setAttribute("title", "page title") for pages.
    Use Lianja.get("page1.section1").setAttribute("title", "section title") for sections.
    Use Lianja.get("page1.section1.field1").setAttribute(" caption", "field caption") for formitems.
    Note that there are shortened forms of these also, setAttr() and getAttr() respectively.



    Q:
    I have a custom commandbutton class that I want to reuse. Meaning, I have several buttons created using "Mybuttons".
    I want to pass a unique id to click event so that I know which button was clicked.

    Something like below.

    Code:
    define class mybuttons as commandButton
            proc click( param1)
                    do case
                      .....
                    endcase
    
    
            endproc 
    enddefine
    A:
    create your button and assign it a unique id. In the click event you can then reference this.id.
    this.name works fine.



    Q:
    When an App is open in App Builder, is it and it's objects available in the Console?
    A:
    Code:
    ? Lianja.get("page.section.control").text


    Q:
    Wher is .hwnd properties in Form object ?
    How do use hwnd to get the id for a section, or a gadget?
    I need to redirect video output to a window.
    A;
    hwnd is a artifact of the (old -- WPF and Silverlight don't have hwnd, but have hwnd interop) windows technology. The purpose was to give a near-object reference in a non-object-oriented environment.
    In LianjaDemo, from the console:

    Code:
    lo = lianja.get("customers")
    ? lo.hwnd


    Q:
    May I know how I can get an object reference to the Current App, Current Page, Current Section, Current field and Current Gadget in my delegate?
    In other words, is there something similiar to This and Thisform in VFP for the App, Page, Section, Field and Gadget
    A:
    Code:
    loMyControl = Lianja.activepage.activesection.activecontrol
    For active page:
    Code:
    oactivePage = Lianja.activePage
    nameactivePage = Lianja.activePage.id
    Section:
    Code:
    oactiveSection = Lianja.get("mypage").activesection
    Lianja.localstorage.setItem( key, value )
    and
    Code:
    Lianja.sessionstorage.setItem( key, value )
    And the corresponding getItem() on these work between desktop and web//mobile
    _screen is VFP desktop specific and does not exist in the web client.



    ​All topics in [Answers] alphabetically:http://www.lianja.com/community/showthread.php?2717-Answers

  4. #4
    Lianja MVP
    Join Date
    Dec 2012
    Location
    Croatia, Zagreb
    Posts
    1,135
    Q:
    I have several forms that I have opened using form.show()
    what would be the best way to reference and then close them programatically?

    A:
    assuming there is no fixed order or choice, I would keep an array with form name + instance identifier and form object references as columns in each row of the array.. The reason for an instance identifier (e.g., <form name> + guid() is for specific identification if a form can be opened more than once.. Then, you can use the array to close all of them. And if a form is closed manually, you can use the form+guid() property on the form to delete the row of the array, which will release the object reference there.




    All topics in [Answers] alphabetically: https://www.lianja.com/community/sho...ll=1#post13748

    These answers are also systematized on the site "Lianja developer": https://lianjadeveloper.wordpress.co...y/referencing/

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