Page 1 of 1

Grouping of groups -- "last group" is wrong

Posted: Mon Jun 09, 2008 4:16 am
by TEDennis

Code: Select all

on groupBug
  -- Add 2 fields to be grouped
  create field "A"
  create field "B"
  group field "A" and field "B"
  -- "last group" refers to the group we just added
  set the name of last group to "G1"
  -- Add 2 more fields to be grouped
  create field "C"
  create field "D"
  group field "C" and field "D"
   -- "last group" refers to the group we just added
  set the name of last group to "G2"
  -- Now, group the two groups we just added
  group group "G1" and group "G2"
  -- oops ....
  put the name of the last group -- SHOULD NOT BE G2, BUT IT IS
  set the name of the last group to "G3" -- RENAMES GROUP G2 TO G3
end groupBug

Posted: Mon Jun 09, 2008 1:55 pm
by BvG
Not a bug in the way you mean, but it's a documentation bug, and you should post it at the quality center.

The last group is always the topmost group (layer with the largest number). if you group a group, the new group is placed at the topmost place. but objects within the group are always at a higher layer then the group that contains them.

So in your example this is the layering (layer number in front), when your code is finished:

Code: Select all

1 group "group id <idnumber>"
2 -> group "G1"
3 - -> field "A"
4 - -> field "B"
5 -> group "G2"
6 - -> field "C"
7 - -> field "D"
As you see, the topmost group is "G2", and the group you actually want is bottommost, because the new group contains all other groups.

The problem is, there's no single way to set names of a newly created group, all methods have some backdraw:
  • the layer (last, topmost etc.) will not work (as seen) if the new group contains groups
  • setting the name of the templategroup will not work if any object in your new group was grouped then ungrouped and you didn't leave the card since then (because in that case the name is set to what the old group was named, see the "ungroup" entry of the docu).
  • using the "newGroup" message is probably the easiest, but not really obvious, and quite a clunky workaround.
  • there's probably other ways that I have forgotten/don't know
Probably RunRev should put the "newgroup" message as an example into the documentation, or fix the group command to put an object reference into the "it" variable, as every other creation of an object does.

Example code (needs to be at card or higher level in the message path):

Code: Select all

on newGroup
  set the name of the target to the newGroupName of me
end newGroup
Example code to rename your group (in mouseUp or groupBug or whatever handler):

Code: Select all

on mouseUp
  set the newGroupName of this card to "G3"
  group group "G1" and group "G2"
end mouseUp

Posted: Mon Jun 09, 2008 6:17 pm
by TEDennis
OK, thanks for the explanation.

I reported the "situation" with a link back to this thread.

BTW, it might be coincidental and therefore unreliable, but the "correct" new name appears as the last entry in the groupnames list.