Re: creating check boxes programmatically by Igor
Igor
Tue Dec 30 11:16:56 CST 2003
Hi, Ee Shan!
You wrote on Mon, 29 Dec 2003 18:15:12 -0800:
ES> Currently, I retrieved information from database into an
ES> array. And I would like to store this value into a set of
ES> checkboxes for users to select.
ES> Below are my code. I have 3 different types of algorithms
ES> but none work.
ES> FOR i = 1 TO ALEN(arr)
* I suggest that "fra1" is a kind of container,
* an object that MAY have another objects inside it :)
* For simplicity try first with the form itself - so
* throw away "fra1" from below code
* Construct unique name for new object.
temp = "chk" + TRANSFORM(m.i)
ES> thisform.fra1.AddObject(temp, "checkbox")
* now find out object reference to newly created object
* note that it is easier to read the code, if you'll use
* another name for object reference, say lcTemp for object name
* and loTemp for object reference itself, but it doesn't really matter
temp = EVAL("thisform.fra1." + m.temp)
ES> temp.caption = TRANSFORM(arr[i])
ES> temp.autosize = .t.
ES> temp.visible = .t.
m.temp.Top = m.i*20
* Otherwise all our checkboxes will sit one over another :)
ES> ctrlarr[i] = temp
* Remove previous line
ES> temp = .null.
* And this line is really of no sence if you'll
* use LOCAL variable "temp" (you really do the best if declare it
* as LOCAL - and of course outside the loop)
ES> NEXT
* For the next sample you have to have "ctrlarr"
* as a form propery (and as an array!) and you
* have to reference it in a corresponding way, like
* ThisForm.ctrlarr[i]
ES> FOR i = 1 TO ALEN(arr)
ES> ctrlarr[i] = CREATEOBJECT("checkbox")
ES> ctrlarr[i].caption = TRANSFORM(arr[i])
ES> ctrlarr[i].autosize = .t.
ES> ctrlarr[i].visible = .t.
ES> NEXT
* Sorry it is a kind of stuff no one can analyse :)
* Array of names, array of values %)
* be a bit simplier :)
ES> FOR i = 1 TO ALEN(arr)
ES> varname = TRANSFORM(ctrlarr[i])
ES> thisform.fra1.NewObject(varname, "checkbox")
ES> &ctrlarr[i].caption = TRANSFORM(arr[i])
ES> &ctrlarr[i].autosize = .t.
ES> &ctrlarr[i].visible = .t.
ES> NEXT
If you really want to have "control array" - google on this term in fox NGs
:) There will be a number of corresponding messages.
P.S. Happy New Year
--
WBR, Igor