Sequential Layout of Script-created Objects

Bernard Devlin revolution at knowledgeworks.plus.com
Sun Dec 8 16:28:48 EST 2002


[My apologies Jeanne - I re-checked the Transcript Dictionary to on the term
"create" and I have no idea where I got the notion that buttons had to be
created in a group.  It is quite clear from the text there that most of the
samples do not create the buttons in a group. Thank you for your forebearance.]

I used (a slightly modified version of) Jeanne's code, and I'm seeing some
strange effects.

This is the code that loops through the controls and (conditionally) deletes
them:

  repeat with x = 1 to the number of controls of group "grpButtons" of stack
"Map"
    put the name of control x of group "grpButtons" of stack "Map" into
theControl
    if word 1 of theControl is "button" then
      delete control theControl of group "grpButtons" of stack "Map"
    end if
  end repeat

However, after a few iterations (and whilst there are still buttons in the
group that are not deleted) I get this error:

>>
 ? There was an Execution Error at 8:35:42 PM
Error description:  Chunk: no such object
Object: button id 1021 of card id 1002 of stack "Mapping Source" of stack
"C:/rev111/keyboardMappings.rev"
--------------------
put the name of control x of group "grpButtons" of stack "Map" into theControl
--------------------
Value: 4
<<

What appears to be happening is that the number of controls is being reduced
because of the deletions, and after a certain point the control to which the
next x refers has been deleted.  This seems like strange behaviour to me.
Should "the number of controls" be re-evaluated on each iteration of the loop?
But the number of iterations of x has been set at the start, and that does not
get re-evaluated.  I have checked this in the debugger and this is what is
happening.  About halfway through the process, the number of controls falls
below the number of the next control to be deleted.

What is the best way round this in Transcript?

> >2) the above code lays any new buttons on top of the old buttons when the code
> >is run again.  I am sure I can get hold of the contents of the group
> >"grpButtons" in order to delete each old button, but I don't know how.

Of course, after my stupidity about thinking I have to create buttons in
groups, I think I must be wrong in my analysis of this problem!



More information about the Use-livecode mailing list