Beijer Electronics (formerly QSI Corporation)

Manufacturer of Mobile Data and Human Machine Interface Terminals.
It is currently Sat Nov 18, 2017 10:35 am

All times are UTC - 7 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Wed Jun 07, 2006 10:27 am 
Offline
QSI Support
QSI Support
User avatar

Joined: Wed Mar 08, 2006 12:25 pm
Posts: 881
Location: Salt Lake City, Utah
Unfortunately Qlarity does not support creating or deleting objects at runtime. All objects must be created at compile time.



In many cases where dynamic creation and deletion of objects is desired, it is possible to achieve the same effect by creating a pool of objects that can then be requested and released.



The following is sample code demonstrating how you can do this with ButtonV2 objects. The procedure is similar for any type of object that you need to pool



Code:

'This code is intended for use in the ADVANCED CODE section of

'the object tree.  Enable Advanced Code by selecting

'Tools->Settings->Editor->"Show advanced code sections..."

library basic source ButtonV2

library basic source ScreenV2



dim FreeButtons[] as objref ButtonV2

init FreeButtons := [dynamicbutton01, dynamicbutton02, dynamicbutton03, dynamicbutton04, dynamicbutton05, dynamicbutton06]



func CreateButton(parent as objref, xPos as integer, yPos as integer, width as integer, height as integer, caption as charstr) returns objref buttonv2

    dim retVal as objref ButtonV2

    if len(freeButtons) == 0 then

        throw ("CreateButton", "No free buttons")

    endif



    retVal = FreeButtons[0]

    FreeButtons = Mid(FreeButtons, 1, -1)



    retVal.parent = parent

    retVal.xPos = xPos

    retVal.yPos = yPos

    retVal.width = width

    retVal.height = height

    retVal.Value = caption

    retVal.enabled = true

    retVal.inactive = false

    return retVal

endfunc



func DestroyButton (button as objref ButtonV2)

    dim tmpArr[1] as objref buttonV2

    tmpArr[0] := button

    button.parent = UnusedObjectsScreen

    button.enabled = false

    FreeButtons := FreeButtons + tmpArr

endfunc



declare UnusedObjectsScreen as ScreenV2

    init enabled := false

enddec



declare DynamicButton01 as ButtonV2

    init enabled := false

enddec

declare DynamicButton02 as ButtonV2

    init enabled := false

enddec

declare DynamicButton03 as ButtonV2

    init enabled := false

enddec

declare DynamicButton04 as ButtonV2

    init enabled := false

enddec

declare DynamicButton05 as ButtonV2

    init enabled := false

enddec

declare DynamicButton06 as ButtonV2

    init enabled := false

enddec





Now, depending on your specific situation a different technique may be more appropriate. Feel free to post on the Qlarity support forums if you have any questions that are specific to your application.

_________________
Jeremy
http://www.beijerinc.com


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 20, 2007 10:55 am 
Offline
User avatar

Joined: Thu Mar 02, 2006 2:12 pm
Posts: 487
Location: Salt Lake City, Utah
Another option might be to initialize the FreeButtons array at startup.



Code:
func Startup ()

    handles MSG_INIT

    dim btn[1] as buttonv2

    dim i as integer



    for i = 1 to 6

        val(btn[0], "dynamicbutton0" + str(i))

        freebuttons = freebuttons + btn

    next



    return

endfunc




Saves from having to type out:

Code:

init FreeButtons := [dynamicbutton01, dynamicbutton02, dynamicbutton03, dynamicbutton04, dynamicbutton05, dynamicbutton06]



which could be a lot of typing if you have 100 buttons.

_________________
Ron L.

http://www.beijerelectronicsinc.com/


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 7 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group