I got a question like this too, but what i used wasn't a form collection, but a buttons collection in a container.like this:
container.init:
___________________________________________
this.buttons = newobject("Collection")
___________________________________________
Container.addbutton:
___________________________________________
LPARAMETERS ckey
LOCAL nCount
nCount = this.buttons.count
** check wether this button have exist
IF TYPE("This.But_"+ cKey) = "O" AND !ISNULL(EVALUATE("This.But_" + cKey))
RETURN
ENDIF
** Add button object
this.AddObject("But_" + cKey, "CommandButton")
** Add the button's ref to collection
this.buttons.add(EVALUATE("this.But_" + cKey), ckey)
With this.buttons.item(ckey)
.caption = ckey
.visible = .T.
endwith
___________________________________________
Container.clear
___________________________________________
local ncount as integer, n as integer
nCount = this.buttons.count
for m.n = nCount to 1 step -1
this.buttons.remove(m.n)
endfor
___________________________________________
In this way, I got several question:
first, i call the container.clear in form's release event, but if i click the form's close button, it's seems the release event will not been fire, i must add 'thisform.release' to form's queryunload events to solve this.
Second, i found that if i use container.removeobject('buttonname'), the ref in collection will be remove automatic also, but not work conversely.
third, if i directly use the collection's add method to create a new button, then you can't see the button anywhere ,even you set the button's visible = .t.. you must add the button to a container, then add ref to collection like i do.And even in my way, Sometimes the buttons will not visible occasional, you must set the visible = .T. again!
Previous
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only