I have tried to demonstrate this problem by giving the reader a step by step process to display the problem and then to show the not entirely satisfactory work around that I have used. The steps and scripts are relatively simple but will take some effort to work through. Here is the procedure:
Start with a new main stack
Drag out a button and drag out a field.
By default they are named 'Button' and ‘Field’
In the mouseUp code for the button put the following script:
Code: Select all
on mouseUp
put the number of this card into tCardNum
put getRandomString(tCardNum) into tString
put tString into field "Field"
end mouseUp
function getRandomString tNum
-- produce a random 4 character string preceeded by the card number
put "" into tString
repeat with i= 1 to 4
put random(26) + 96 into tAscii
put numToChar(tAscii) after tString
end repeat
return tNum & "-" & tString
end getRandomString
Now go to the Object Menu and take New Card. No surprise. The new card is blank. Go ahead and delete it.
Back on card 1 select the button and the field and take the option to Group them.
Now go to the Property Inspector and check the box ‘Behave like a background’ from the ‘Basic Properties’ choices.
Now make a new card or two and you will see both the button and the field on them. Use the View Menu to go from card to card. Click the button on each card a number of times. You should always get the card number followed by a random string placed in the field. This is what I think of as typical behavior for a stack of cards with a common background.
Delete all but one of your cards preferably keeping a card which is not showing a ‘1’. Click the button again and it should now show a ‘1’.
Go to the Tools palette and drag out a DataGrid. By default it should be named ‘DataGrid 1’. Open the property inspector for the new datagrid and in the Contents option type the word ‘one’ followed by a tab, then followed by the word ‘two’ and then a tab and follow that with the word ‘three’ followed by a return.
Close the Inspector and you should see a three column grid with column headings ‘Col 1’, ‘Col 2’, ‘Col 3’ and the data ‘one’, ‘two’, ‘three’ in the top and only row of data. You may need to size the grid so that you can see all three columns.
The data is ours but the column headings were placed there by default. Select the DataGrid again and go to Property Inspector and the Columns tab and let’s change the Column headings by changing the ‘column name’ for each column. Change them to ‘Heading 1’, ‘Heading 2’ and ‘Heading 3’ so that everything is our information and nothing is there by default.
Now we will change our mouseUp script to include some actions to the DataGrid. Copy the script below and paste it so that it completely replaces the script in the button.
Code: Select all
on mouseUp
put the number of this card into tCardNum
put getRandomString(tCardNum) into tString
put tString into field "Field"
put ComposeGrid(4,tCardNum) into tText
set the dgText of group "DataGrid 1" to tText
end mouseUp
function getRandomString tNum
-- produce a random 4 character string preceeded by the card number
put "" into tString
repeat with i= 1 to 4
put random(26) + 96 into tAscii
put numToChar(tAscii) after tString
end repeat
return tNum & "-" & tString
end getRandomString
function ComposeGrid tLines tCard
-- produce tLines rows of random text with each row containing three columns of data
put empty into tGridText
repeat with i = 1 to tLines
put getRandomString(tCard) & Tab & getRandomString(tCard) & Tab & getRandomString(tCard) & return after tGridText
end repeat
return tGridText
end ComposeGrid
You can take my word for this but if you were to create a new card now, it would not contain the data grid because the grid is not part of the background. Let’s fix that.
Select the group that contains the button and the field. Then go to the Objects menu and take the choice for ‘UnGroup Selected’. Now select all three – button, field and dataGrid and then take the ‘Group Selected’ choice from the Objects menu.
Create 2 new cards and look at them but don’t press the button. This is where I got my first surprise. Notice that the dataGrid is in both the new cards but there are no headings.
Go back to the first card and press the button. Still looks good.
Go to the second card and press the button. We have the data that reflects card 2 but no headings.
Go back to the first card and you will see that it has headings but now has no data.
Go ahead and click the button card 1. Back to looking OK.
Now look at card 2. Nothing.
Alternate between the three cards clicking the button on each and then look at the other cards. The click produces the correct data for each card but the other cards loose theirs. The only card that shows both the headings and the data is card 1.
Go back to card 1 and click the button to get the headings and data on the same card. Delete the other two cards.
On this first and only card which still works fine, select the group containing the three controls and then UnGroup them. Select just the button and the field and put them back into their own group.
Make two new cards. If you examine them you will see that the new cards are missing their dataGrid. A click of the button on either of these will cause an error because the mouseUp script makes reference to ‘DataGrid 1’ which is not present.
Go back to card 1 and select just the dataGrid. Use the Edit Menu to copy it. Finally go to both cards 2 and 3 and paste the grid on each one. Each of the cards now has a grid with headings and data but in every case the data is the same (i.e. from card 1).
Cycle through the three cards pressing the button on each. Each one works fine and does just what I intended. Problem solved by the work around of using a copy of the original dataGrid on each card rather than placing the grid in the background.
The solution works but is not really satisfactory because each of those similar looking grids are independent of each other. If I should happen to resize or re-position the grid on one card for some reason, the others would have to be adjusted accordingly. If in a later stage of development I should need to add script to the dataGrid for some reason, it would have to be added to the grid in each card.
Did I have other choices for ways to handle this problem or was my work around the way others would do it? Any suggestions or references would be appreciated.
Thanks,
Larry