This command creates a bunch of Fields as buttons inside a group (for scrolling) depending on a variable number of Records in an SQLite Table passed as "SelectorList".
This variable bLeft ( at the *) initially may get 43
at ** I use this to set the Left of my Field.
Nothing else is done to the variable and when I step through the loop, bLeft never changes.
BUT:
the first Field created gets a Left of 39, all the others get the expected 43.
Where am I wrong?
command buildButtonsList SelectorList
global D, F, L, S
lock screen
put empty into S["msg"]
put the top of group "Buttons" +8 into bTop
* put the left of group "Buttons" +8 into bLeft
put (L["ButtonWidth"] - the scrollbarWidth of me) into bWidth
repeat for each element tItem in SelectorList
put "Sel" & tItem["Key"] into selectFieldName
create field selectFieldName in group "Buttons"
# set the behavior of it to the long ID of button "SelectMaster"
set the script of field selectFieldName to the script of button "SelectMaster"
set the cID of field selectFieldName to tItem["Key"]
set the backColor of field selectFieldName to L["Col_FieldBG"]
set the opaque of field selectFieldName to true
set the textSize of field selectFieldName to L["FS_Large"]
set the margins of field selectFieldName to 12
set the unicodetext of field selectFieldName to uniencode (tItem["Info"],"UTF8")
set the locktext of field selectFieldName to true
set the traversalOn of field selectFieldName to false
set the width of field selectFieldName to bWidth
set the height of field selectFieldName to the formattedheight of field selectFieldName
set the top of field selectFieldName to bTop
** set the left of field selectFieldName to bLeft
put the bottom of field selectFieldName +8 into bTop
end repeat
For Information:
this is a sequence of selections with each step producing a different set of buttons, depending on all previous selections, so I mostly have to ( clear and ) rebuild the group.
In the rare case that I want to see the same selection a second time (i. e. just removing all the Fields and building the same list again) all the fields get the correct left of 43.
Beats me!
strange behaviour of a Variable inside a loop
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: strange behaviour of a Variable inside a loop
Hi.
Unlock the screen. When you step through the handler, are the proper values of bLeft and fld selectFieldName all in order? When you execute the line that sets the "left", where does it go? Where should it? Where does the next one go, and how did it get there?
Craig Newman
Unlock the screen. When you step through the handler, are the proper values of bLeft and fld selectFieldName all in order? When you execute the line that sets the "left", where does it go? Where should it? Where does the next one go, and how did it get there?
Craig Newman
Re: strange behaviour of a Variable inside a loop - solved
Thx Craig,
I never thought of unlocking the screen (it makes quie a difference in performance with this kind of operation).
The problem lies in the Position and size properties of a group - they obviously change, whe we add Objects above or farther left than what it previously held.
This certainly deserves some investigation, here I could solve it by creating an (invisible) empty field before looping through the buttons, that works even if I don't give it a position.
Andreas
I never thought of unlocking the screen (it makes quie a difference in performance with this kind of operation).
The problem lies in the Position and size properties of a group - they obviously change, whe we add Objects above or farther left than what it previously held.
This certainly deserves some investigation, here I could solve it by creating an (invisible) empty field before looping through the buttons, that works even if I don't give it a position.
Andreas
Re: strange behaviour of a Variable inside a loop
I am sure you will fix this. And yes, the overall extent of a group can easily change if you meddle with its members.
Unlocking makes the step=by-step examination of this sort of thing accessible, or at least possible.
Craig
Unlocking makes the step=by-step examination of this sort of thing accessible, or at least possible.
Craig