Buttons in groups - Odd "feature" ?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Simon Knight
Posts: 854
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Buttons in groups - Odd "feature" ?

Post by Simon Knight » Sat Apr 14, 2018 5:03 pm

I have an application that was working then I updated it. It is a stack with two cards. The principle card displays a number of buttons configured as pick lists. These lists update depending on user selection. The data selection handlers are stored in the stack and these write data to the controls on the card. As I said this was all working. Then...... I placed some of the buttons into a group. Now I seem unable to write data to these particular buttons when using my handler which is passed the name of the button. These two lines demonstrate the problem:

Code: Select all

  -- Hard code of button name works
   set the text of button "SetProject" of card "notes" of this stack to tListOfItems
   
   -- Soft code of button name fails when button is in a group 
  set the text of button pNameOfControl of card "notes" of this stack to tListOfItems
Just to be clear button "SetProject" is in group "MiddleButtonBar" on card "Notes". Also the soft code line works with buttons that are just on the card.

I have tried adding quotes, adding references to the group, expanding the names to full in the variable passed : an example here:

Code: Select all

put quote & "SetProject" & quote & " of group " & quote & "MiddleButtonBar" & quote into tNameOfControl
Please point out the error of my ways.
best wishes
Simon
best wishes
Skids

Randy Hengst
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 153
Joined: Thu Jun 29, 2006 4:16 pm

Re: Buttons in groups - Odd "feature" ?

Post by Randy Hengst » Sat Apr 14, 2018 8:05 pm

Would something like this help?

put "SetProject,MiddleButtonBar" into tNameOfControl

set the text of btn item 1 tNameOfControl of grp item 2 tNameOfControl of card "notes" of this stack to tListOfItems

randy hengst

Simon Knight
Posts: 854
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: Buttons in groups - Odd "feature" ?

Post by Simon Knight » Sat Apr 14, 2018 11:23 pm

Unfortunately it seems that the line fails if any variable is used to refer to the button. My complete kludge is to use a Switch statement to select between buttons on the card and those in the group:

Code: Select all

   Switch pNameOfControl
      Case "SetProject"
         set the text of button "SetProject"  of card "Notes" of this stack to tListOfItems
         break
      Case "SetPriority"
         set the text of button "SetPriority"  of card "Notes" of this stack to tListOfItems
         break
         Case "SetTask"
         set the text of button "SetTask"  of card "Notes" of this stack to tListOfItems
         break
          Case "SetActionee"
         set the text of button "SetActionee"  of card "Notes" of this stack to tListOfItems
         break
      default
         set the text of button pNameOfControl  of card "Notes" of this stack to tListOfItems
   end Switch
   
   unlock screen
The default section of the Switch works with the buttons that are on the card and the other named sections refer to buttons that are in the group on the card.

My first thought was that I should include the group name in the variable pNameOfControl (see last code line in my first post) but it did not work and is unnecessary. This kludge works but seems to show that something odd is happening : I am unable to refer to the buttons in the group using a variable hence the four lines of explicit button names inside their own case statements.

Simon
best wishes
Skids

Randy Hengst
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 153
Joined: Thu Jun 29, 2006 4:16 pm

Re: Buttons in groups - Odd "feature" ?

Post by Randy Hengst » Sun Apr 15, 2018 1:20 pm

The code I sent before does "work." But, I'm not sure what you're trying to accomplish. Where are you placing the code you're referencing? Is it in each of the buttons of the group? Here's another idea... the handler would go in card or stack script... then called in each of the buttons in your group.

on setMyList pButtonName,pNameOfGroup
set the text of btn pButtonName of grp pNameOfGroup of card "notes" of this stack to tListOfItems
end setMyList

on mouseDown
setMyList (short name of target),(owner of target)
end mouseDown

randy hengst

Lagi Pittas
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 365
Joined: Mon Jun 10, 2013 1:32 pm

Re: Buttons in groups - Odd "feature" ?

Post by Lagi Pittas » Sun Apr 15, 2018 1:26 pm

Hi Simon

Are you passing the long name ie default name of the button as the parameter rather than the short name .. worth a punt?

Regards Lagi

Simon Knight
Posts: 854
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: Buttons in groups - Odd "feature" ?

Post by Simon Knight » Sun Apr 15, 2018 6:32 pm

Hi Both,

Randy asks what I am attempting to accomplish? Well I have several handlers in the card script that build different lists of text and them write these lists into list buttons on the first card.

The writing of the lists to the buttons is accomplished with the line :

Code: Select all

set the text of button pNameOfControl  of card "Notes" of this stack to tListOfItems
where pNameOfControl is the short name of the button and tListOfItems is the text list.
This line works fine with buttons that are "just" on the card. It fails with buttons that are in a group on the card.

I have tried many different naming conventions including passing button "fred" of group "dick" but in every case it seems that Livecode is unable to locate the button when it is in a group and is referenced by a variable i.e. pNameOfControl.

The kludge listed above demonstrates that the correct name is being passed and that if the button name is hard coded then all is well and the data is written.

I wanted to check with the forum that I was not making a simple error before raising a bug report.
best wishes
Skids

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9823
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Buttons in groups - Odd "feature" ?

Post by FourthWorld » Sun Apr 15, 2018 7:25 pm

Simon Knight wrote:
Sun Apr 15, 2018 6:32 pm
The writing of the lists to the buttons is accomplished with the line :

Code: Select all

set the text of button pNameOfControl  of card "Notes" of this stack to tListOfItems
where pNameOfControl is the short name of the button and tListOfItems is the text list.
This line works fine with buttons that are "just" on the card. It fails with buttons that are in a group on the card.
Is the backgroundBehavior of the group set to true?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9823
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Buttons in groups - Odd "feature" ?

Post by FourthWorld » Sun Apr 15, 2018 7:26 pm

Simon Knight wrote:
Sun Apr 15, 2018 6:32 pm
The writing of the lists to the buttons is accomplished with the line :

Code: Select all

set the text of button pNameOfControl  of card "Notes" of this stack to tListOfItems
where pNameOfControl is the short name of the button and tListOfItems is the text list.
This line works fine with buttons that are "just" on the card. It fails with buttons that are in a group on the card.
Is the backgroundBehavior of the group set to true? And what is the value of the button's sharedText property?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Randy Hengst
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 153
Joined: Thu Jun 29, 2006 4:16 pm

Re: Buttons in groups - Odd "feature" ?

Post by Randy Hengst » Sun Apr 15, 2018 7:46 pm

The short name of the button is "myShortName" not "myShortName of grp myGroup". That looks like what you're placing in the variable. I don't think that's a bug. It's just how it works. If that's not the case, I'm happy to learn something new.

When you put the name of the group in a separate variable, things work fine.

randy hengst

Simon Knight
Posts: 854
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: Buttons in groups - Odd "feature" ?

Post by Simon Knight » Sun Apr 15, 2018 7:50 pm

Hi Richard,

1) The group is not a background.
2) I think the sharedtext property only applies to fields: the message box returns an error of "object is not a container".

A couple of posts above I included a kludge that uses a Switch statement that calls what I am calling lines of code that have the short name hardcoded these work fine. The "feature" arises if the line that uses a variable to describe the button name. Here is the code snip again:

Code: Select all

Switch pNameOfControl
      Case "SetProject"
         set the text of button "SetProject"  of card "Notes" of this stack to tListOfItems
         break
      Case "SetPriority"
         set the text of button "SetPriority"  of card "Notes" of this stack to tListOfItems
         break
         Case "SetTask"
         set the text of button "SetTask"  of card "Notes" of this stack to tListOfItems
         break
          Case "SetActionee"
         set the text of button "SetActionee"  of card "Notes" of this stack to tListOfItems
         break
      default
         set the text of button pNameOfControl  of card "Notes" of this stack to tListOfItems
   end Switch
   
   unlock screen
 
The handler is passed the short name of the button which is stored in pNameOfControl and it builds a list of values which get stored in tListOfItems.

When pNameOfControl is the name of a button on the card the line in the default section is called and the button is updated. When pNameOfControl is one of the four in the group e.g. "SetPriority" then the Case statement fires and the line with the hard coded is called and the button updates. Note that the group name is not used or needed. If however the Case statement is disabled meaning that the default line is called with for example "SetPriority" then an error is raised as the engine is unable to find the button.

In short : why does this line fail when the button is in a group on the card ?

Code: Select all

set the text of button pNameOfControl  of card "Notes" of this stack to tListOfItems
best wishes
Skids

Simon Knight
Posts: 854
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: Buttons in groups - Odd "feature" ?

Post by Simon Knight » Sun Apr 15, 2018 8:08 pm

Arrg!

Please ignore all of the above and my apologies for time wasting.

The simple single line that uses a variable is now working whereas yesterday it was not. I have no idea why it was not working yesterday possibly "ghosts in the machine". The only change is that the computer has been restarted.
best wishes
Skids

bwmilby
Posts: 438
Joined: Wed Jun 07, 2017 5:37 am
Location: Henrico, VA
Contact:

Re: Buttons in groups - Odd "feature" ?

Post by bwmilby » Sun Apr 15, 2018 8:26 pm

Code: Select all

of button tCtrl of ...
the variable there can only reference the short name of the button

But the following should work

Code: Select all

function q pText
    return quote & pText & quote
end q

put "button" && q(tCtrl) \
    && "of group" && q("g1") \
    && "of card" && q("c1") \
    && "of stack" && q("s1") into tLongCtrl

set the text of tLongCtrl to tList
(Edited to remove smart quotes)
Brian Milby

Script Tracker https://github.com/bwmilby/scriptTracker

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”