Results 1 to 10 of 10

Thread: Programmatic class confusion.

  1. #1
    Member
    Join Date
    May 2012
    Posts
    37

    Programmatic class confusion.

    I have this in a .VCP file called formclasses.vcp:

    Code:
    define class basebutton as commandbutton
    	
    	** Properties
    	Height = 27
    	Width = 84
    	FontName = "Tahoma"
    	FontSize = 8
    	Caption = "caption"
    	Name = "basebutton"
    	
    enddefine
    
    
    
    define class basebutton1 as basebutton
    	
    	** Properties
    	Top = 36
    	Left = 36
    	Name = "Basebutton1"
    	
    	** Methods
    	PROCEDURE Click
    		
    		MessageBox("Base form click.")
    	ENDPROC
    	
    	
    enddefine
    I have the following in a .PRG file:

    Code:
    set procedure to formclasses.vcp additive
    loButton = createobject("basebutton")
    debugout print_r(loButton)
    loButton2 = createobject("basebutton1")
    debugout print_r(loButton2)
    The output from running the .PRG at the console is that the first button is created properly:

    Code:
    Object (refcnt=1)
    (
        [height] => 27
        [width] => 84
        [fontname] => Tahoma
        [fontsize] => 8
        [caption] => caption
        [name] => basebutton
    )
    ... but the second throws an error:

    Code:
    Wed 28. Jan 17:03:55 2015
    **** Lianja error ****
    createobject("basebutton1")
                              ^
    CLASS 'basebutton1' not found
    Called from program   - classestest.dbo at line 4

    Why?

  2. #2
    Senior Member
    Join Date
    Feb 2012
    Posts
    1,239
    Hi Alan,

    I just tried this and it is working for me.

    The only difference is that I used a .prg file extension, not .vcp

    set procedure to formclasses.prg additive
    loButton = createobject("basebutton")
    debugout print_r(loButton)
    loButton2 = createobject("basebutton1")
    debugout print_r(loButton2).

    I get
    Object (refcnt=1)
    (
    [height] => 27
    [width] => 84
    [fontname] => Tahoma
    [fontsize] => 8
    [caption] => caption
    [name] => basebutton
    )
    Object (refcnt=1)
    (
    [height] => 27
    [width] => 84
    [fontname] => Tahoma
    [fontsize] => 8
    [caption] => caption
    [name] => Basebutton1
    [top] => 36
    [left] => 36
    )

    I am using a late beta version, so that may possibly be it too.

    Herb

  3. #3
    Senior Member
    Join Date
    Feb 2012
    Posts
    1,239
    Just a thought.

    Try adding it to a custom VFP section. In my case, I am getting the messagebox to appear when clicking the second button.


    Here's my init.

    proc init()
    set procedure to formclasses.prg additive
    endproc

    Here's the section code

    proc page1_section2
    page1_section2 = createobject("page1_section2")
    page1_section2.addObject("button1","basebutton")
    page1_section2.addObject("button1","basebutton1")

    return page1_section2

    Herb

  4. #4
    Lianja Development Team barrymavin's Avatar
    Join Date
    Feb 2012
    Location
    UK, USA, Thailand
    Posts
    6,246
    Hi Alan,

    Try using SET CLASSLIB rather than SET PROCEDURE and omit the file extension.
    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
    Lianja Development Team barrymavin's Avatar
    Join Date
    Feb 2012
    Location
    UK, USA, Thailand
    Posts
    6,246
    Hi Alan,

    set classlib does in fact work as expected. Although set procedure will handle class definitions it is better to use set classlib.

    In the console.

    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.

    A few other 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
    Also, please be aware of this in Lianja (borrowed from PHP).

    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.

    Name:  Screen Shot 2015-01-29 at 10.40.56 AM.jpg
Views: 88
Size:  85.5 KB

    Name:  Screen Shot 2015-01-29 at 10.43.15 AM.jpg
Views: 188
Size:  97.3 KB

    Also note that in Lianja version 2 as stated in the development roadmap:

    • Visual Form/Dialog Builder that works with existing VFP .scx and .vcx files.
    • Visual Component Builder with the ability to use custom UI classes in form, canvas and custom sections.

    You can in fact use custom UI classes in custom sections already but in v2 there will be a more graphical integration to provide the ability to design these visually.

    Clearly Lianja will evolve over time and rome was not built in a day as the old saying goes.
    Last edited by barrymavin; 2015-01-28 at 23:49.
    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

  6. #6
    Member
    Join Date
    May 2012
    Posts
    37
    Thank you all, will dig through all this info!

  7. #7
    Member
    Join Date
    May 2012
    Posts
    37
    I have discovered that I need to put a SET CLASSLIB TO at the start of my main PRG where I instantiate the classes, as otherwise it doesn't seem to pick up changes to the two class library PRGs even if everything is recompiled.

  8. #8
    Lianja Development Team barrymavin's Avatar
    Join Date
    Feb 2012
    Location
    UK, USA, Thailand
    Posts
    6,246
    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.
    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

  9. #9
    Lianja Development Team barrymavin's Avatar
    Join Date
    Feb 2012
    Location
    UK, USA, Thailand
    Posts
    6,246
    So once you have your app all working you can start using require_once() as described earlier in this thread.
    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

  10. #10
    Member
    Join Date
    May 2012
    Posts
    37
    Have it all working now, a combination of the tips above and me actually reading what it says on the screen LOL

Tags for this Thread

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