Group objects "Lessons Learned" & question
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- VIP Livecode Opensource Backer
- Posts: 244
- Joined: Wed May 11, 2011 7:50 pm
- Location: Southern California
Group objects "Lessons Learned" & question
I bring items to the forum for 2 reasons: 1. to get answers/advice from more experienced users and 2 . to expose other users to problems that I am having with LiveCode.
Call this "Lessons Learned"
I have been working with Group Objects as of late. I thought I was having good experiences using code that would discover the fields in groups and low and behold I fell into a Rabbit hole and everything went to hell.
this is an example of some of the code:
repeat with xfield = 1 to the number of fields in group "grpTest"
set the lockText of field xField to false
put the short name of field xField into tField
end repeat
This code seemed to work just fine and I was actually able to loop through legitimate fields in my group. But, The idea was to loop through only the fields that are contained in the group and ignore other objects on the card. I only included the fields and not the labels. BUT, as I added other groups onto the card, things got hinky. The code seemed to have lost focus on the named Group and started looking at all of the fields on the card. This was fairly frustrating and required many hours of trying remedy the situation. I tried and re-tried to re-code and exam what was happening. I removed and replaced, renamed groups and everything that I could think of. No such luck. Other weird anomalies were happening also - I seemed to have lost the ability to capture the "On MouseUp" commands and had to use the "right click" of my mouse to make a "MouseUp" command.
Finally I was forced to the LiveCode dictionary to see what was happening.
I discovered the "the ChildControlName" command. I had to use a little more of a verbose script to do the same thing but it worked.
Sample Code:
put the childControlNames of group "Test" into grList
# ENABLE PROJECT INFORMATION GROUP
# ALL FIELDS ARE DEFAULTED TO LOCKTEXT IS TRUE
repeat with xfield = 1 to the number of lines of grList
put line xfield of grList into tField
set the lockText of field tField to false
set the foreGroundColor of field tField to "red"
end repeat
This works just the way I wanted it to do.
So, Question:
Has anyone used the first bit of code :"repeat with xfield = 1 to the number of fields in group "grpTest" or similar with any success? Especially with multiple groups on a card. I was obviously wrong with my assumptions of how this was to work - or is this a bug in LiveCode that needs to be placed in a bug report? I know that Groups with Nested Groups can throw the message path for a loop. But this is not a nested group.
Any comments or recommendations would greatly be appreciated. If not for myself but for the education of other LiveCoders out there.
Call this "Lessons Learned"
I have been working with Group Objects as of late. I thought I was having good experiences using code that would discover the fields in groups and low and behold I fell into a Rabbit hole and everything went to hell.
this is an example of some of the code:
repeat with xfield = 1 to the number of fields in group "grpTest"
set the lockText of field xField to false
put the short name of field xField into tField
end repeat
This code seemed to work just fine and I was actually able to loop through legitimate fields in my group. But, The idea was to loop through only the fields that are contained in the group and ignore other objects on the card. I only included the fields and not the labels. BUT, as I added other groups onto the card, things got hinky. The code seemed to have lost focus on the named Group and started looking at all of the fields on the card. This was fairly frustrating and required many hours of trying remedy the situation. I tried and re-tried to re-code and exam what was happening. I removed and replaced, renamed groups and everything that I could think of. No such luck. Other weird anomalies were happening also - I seemed to have lost the ability to capture the "On MouseUp" commands and had to use the "right click" of my mouse to make a "MouseUp" command.
Finally I was forced to the LiveCode dictionary to see what was happening.
I discovered the "the ChildControlName" command. I had to use a little more of a verbose script to do the same thing but it worked.
Sample Code:
put the childControlNames of group "Test" into grList
# ENABLE PROJECT INFORMATION GROUP
# ALL FIELDS ARE DEFAULTED TO LOCKTEXT IS TRUE
repeat with xfield = 1 to the number of lines of grList
put line xfield of grList into tField
set the lockText of field tField to false
set the foreGroundColor of field tField to "red"
end repeat
This works just the way I wanted it to do.
So, Question:
Has anyone used the first bit of code :"repeat with xfield = 1 to the number of fields in group "grpTest" or similar with any success? Especially with multiple groups on a card. I was obviously wrong with my assumptions of how this was to work - or is this a bug in LiveCode that needs to be placed in a bug report? I know that Groups with Nested Groups can throw the message path for a loop. But this is not a nested group.
Any comments or recommendations would greatly be appreciated. If not for myself but for the education of other LiveCoders out there.
Clarence Martin
chipsm@themartinz.com
chipsm@themartinz.com
Re: Group objects "Lessons Learned" & question
Hi Clarence,
not sure I understand you correctly, but if you use this -> repeat with xfield = 1 to the number of fields OF group "grpTest"
then you need to:
Since xField is just a number and LC will start with field 1 on the current card if you omit "...of grp "grpTest"!
Best
Klua
not sure I understand you correctly, but if you use this -> repeat with xfield = 1 to the number of fields OF group "grpTest"
then you need to:
Code: Select all
...
repeat with xfield = 1 to the number of fields OF group "grpTest"
set the locktext of fld xFiled OF GRP "grpTest"
## more stuff...
end repeat
...
Best
Klua
-
- VIP Livecode Opensource Backer
- Posts: 244
- Joined: Wed May 11, 2011 7:50 pm
- Location: Southern California
Re: Group objects "Lessons Learned" & question
Hi Klaus,
are you saying the key word for this script is "of" Group, not "in" Group that I was using?
are you saying the key word for this script is "of" Group, not "in" Group that I was using?
Clarence Martin
chipsm@themartinz.com
chipsm@themartinz.com
-
- VIP Livecode Opensource Backer
- Posts: 244
- Joined: Wed May 11, 2011 7:50 pm
- Location: Southern California
Re: Group objects "Lessons Learned" & question
Klaus,
after some thought, using "of" makes sense to me. I didn't think about that.
Thanks again you are always most helpful with my questions.
after some thought, using "of" makes sense to me. I didn't think about that.
Thanks again you are always most helpful with my questions.
Clarence Martin
chipsm@themartinz.com
chipsm@themartinz.com
-
- VIP Livecode Opensource Backer
- Posts: 9647
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Group objects "Lessons Learned" & question
Hi.
If I get your issue, why not simply include a "filter" in the loop (pseudo):
This may run into trouble with nested groups, if the groupOfInterest is an enclosing group, but you can script your way out of that as well, by checking to see if the owner of the groupOfInterest is also a group, etc...
Craig Newman
If I get your issue, why not simply include a "filter" in the loop (pseudo):
Code: Select all
if the owner of fld xField = theGroupOfInterest then...
Craig Newman
-
- VIP Livecode Opensource Backer
- Posts: 244
- Joined: Wed May 11, 2011 7:50 pm
- Location: Southern California
Re: Group objects "Lessons Learned" & question
Craig,
That may work, I'll explore that.
It does seem to be a little more code, depending on how many objects are on your card.
Thanks, all suggestions are valuable even for later use.
That may work, I'll explore that.
It does seem to be a little more code, depending on how many objects are on your card.
Thanks, all suggestions are valuable even for later use.
Clarence Martin
chipsm@themartinz.com
chipsm@themartinz.com
-
- VIP Livecode Opensource Backer
- Posts: 9647
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Group objects "Lessons Learned" & question
Hi.
"of" and "in" are synonyms, I think in all cases, but do not hold me to that. Anyway, for me, "of" is my go-to keyword, since I read:
more naturally than
Otherwise it is a matter of style.
Craig
"of" and "in" are synonyms, I think in all cases, but do not hold me to that. Anyway, for me, "of" is my go-to keyword, since I read:
Code: Select all
the number of lines of soAndSo
answer the loc of fld 1
Code: Select all
the number of lines in soAndSo
answer the loc in fld 1
Craig
-
- VIP Livecode Opensource Backer
- Posts: 244
- Joined: Wed May 11, 2011 7:50 pm
- Location: Southern California
Re: Group objects "Lessons Learned" & question
OK, my report back.
Klaus, using "OF" group in the code above does not work, nothing changed.
I went back to the code and tried.
Craig, I have not tried the "if the owner of fld xField = theGroupOfInterest then..." yet. But I may use that elsewhere.
But apparently Of and The are not the same and neither work in this use case.
Klaus, using "OF" group in the code above does not work, nothing changed.
I went back to the code and tried.
Craig, I have not tried the "if the owner of fld xField = theGroupOfInterest then..." yet. But I may use that elsewhere.
But apparently Of and The are not the same and neither work in this use case.
Clarence Martin
chipsm@themartinz.com
chipsm@themartinz.com
Re: Group objects "Lessons Learned" & question
Hi Clarence,
I was only emphasizing the OF since this is the official syntax, although IN will work, too,
and I have been using LC since the MetaCard days in 1999 and found (and experienced!) that
the engine gets a bit pickier with every new release and so one day IN might be deprecated
and you will be happy to have stuck to the official syntax ever since!
Best
Klaus
no, the key to "success" in this case is the addtion of "...of/in grp "groupTest" at all, as my last sentenced explained.chipsm wrote:Hi Klaus,
are you saying the key word for this script is "of" Group, not "in" Group that I was using?
I was only emphasizing the OF since this is the official syntax, although IN will work, too,
and I have been using LC since the MetaCard days in 1999 and found (and experienced!) that
the engine gets a bit pickier with every new release and so one day IN might be deprecated
and you will be happy to have stuck to the official syntax ever since!
Best
Klaus
Re: Group objects "Lessons Learned" & question
Hi Clarence,
Just made a test with some grouped fields and this script:
and it worked as advertized!
What am I missing?
Best
Klaus
hm, don't get it!?chipsm wrote: Klaus, using "OF" group in the code above does not work, nothing changed.
Just made a test with some grouped fields and this script:
Code: Select all
on mouseUp
repeat with i = 1 to the num of fields of grp 1
set the locktext of fld i of grp 1 to TRUE
end repeat
end mouseUp
What am I missing?
Best
Klaus
-
- VIP Livecode Opensource Backer
- Posts: 244
- Joined: Wed May 11, 2011 7:50 pm
- Location: Southern California
Re: Group objects "Lessons Learned" & question
Klaus,
I don't know.
when I initially did this script, it worked. Now,it does not recognise my group and stars with other objects on my card.
I am completely baffled.
I am just going to use ""the ChildControlName" command for now. It has been working flawlessly for now.
I even tried the LiveCode version 8.1.2 instead of the 9.0 (dp 6).
I'll post any problems using this my changes.
I don't know.
when I initially did this script, it worked. Now,it does not recognise my group and stars with other objects on my card.
I am completely baffled.
I am just going to use ""the ChildControlName" command for now. It has been working flawlessly for now.
I even tried the LiveCode version 8.1.2 instead of the 9.0 (dp 6).
I'll post any problems using this my changes.
Clarence Martin
chipsm@themartinz.com
chipsm@themartinz.com
-
- VIP Livecode Opensource Backer
- Posts: 7228
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Group objects "Lessons Learned" & question
Klaus is pointing out that you need to include a complete field reference inside the loop, not just in the repeat declaration. It works fine if you remember to do that.
Inside the loop, the engine has no idea that the field number in the variable means the number of the field relative to the group. It will act on the field relative to the card unless you specify the group it belongs to.
Inside the loop, the engine has no idea that the field number in the variable means the number of the field relative to the group. It will act on the field relative to the card unless you specify the group it belongs to.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- VIP Livecode Opensource Backer
- Posts: 9647
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Group objects "Lessons Learned" & question
What Jacque said.
This is very important, and not well documented.
Make five buttons on a new card. They will be numbered from 1 to 5. Well and good. Now group the last two.
From the msg box,
The first btn is selected.
Now
The "fourth" btn is selected.
Craig
This is very important, and not well documented.
Make five buttons on a new card. They will be numbered from 1 to 5. Well and good. Now group the last two.
From the msg box,
Code: Select all
select btn 1
Now
Code: Select all
select btn 1 of grp 1
Craig
Re: Group objects "Lessons Learned" & question
I really thought I had put that clear!
Not?
Not?
-
- VIP Livecode Opensource Backer
- Posts: 7228
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Group objects "Lessons Learned" & question
It was clear to me. But after I saw the OP's confusion I explained it in different words.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com