Page 1 of 1
Best way to include stack1 in another stack
Posted: Fri Feb 21, 2020 6:33 pm
by dntknwjck
Hello
Need some help with including separate stacks and cards in a new stack.
For example I have a stack that creates a calendar that picks the day that was clicked on, (in a data grid). That I want to use in another stack as a picker.
Tried "start using stack" but could not make that work also tried copying the objects from one stack to the other one, but I don't want to multiple copies work with.
There is probably an easy way to do this but I haven't been able to find it.
Thanks
Re: Best way to include stack1 in another stack
Posted: Fri Feb 21, 2020 6:39 pm
by Klaus
Hi dntknwjck,
every object is bound to ONE stack, so this is not possible without copying,
if I understood you correctly.
However copying data from one stack (datagrid) to another is a snap!
Best
Klaus
Re: Best way to include stack1 in another stack
Posted: Fri Feb 21, 2020 8:50 pm
by dunbarx
Hi.
If I understand what you are trying to do, the problem is not accessing the controls of one stack from another, it is that certain controls, that is, the table field and the dataGrid, are difficult to access that way. Here is an experiment that you might find useful if you want to try to kluge this. Make two new stacks. Name one "xxx" and the other "yyy". In stack "xxx" make a button and name it "b1". In stack "yyy" make a button and name it "b2".
In the script of btn "b1:
Code: Select all
on mouseUp
set the clipBoardData to random(999)
end mouseUp
In the script of btn "b2":
Code: Select all
on mouseUp
send "mouseUp" to btn "b1" of stack "xxx"
-- click at the loc of btn "b1" of stack "xxx" -- ANOTHER WAY
answer the clipBoardData
end mouseUpp
Works fine; you get a number every time you click on "b2". Either line above will do the trick.
But from what I said above, it is not easy to click at some loc of either of those two controls. You do not get the response you want. The dataGrid especially only likes direct mouse clicks. It does a lot with that simple action. There are kluges discussed here about ways to fool it.
But you might try your own kluge. Write back if you do.
Craig
Re: Best way to include stack1 in another stack
Posted: Mon Mar 02, 2020 10:34 pm
by dntknwjck
Craig
Thanks for the example. That is not exactly what I am trying to do. I guess my original question was not clear.
I have built a calendar using a DataGrid to use as a date picker. At this time I have a main stack and a subStack with the calendar on the subStack.
I know I could rename this and continue on with my project but then I end up with the same code in several places and maintenance becomes a problem.
Is there a way to reuse or import the original subStack into another application?
I know this can be done with script using a script only stack.
I have tried to copy and past but that doesn't work well with the DataGrid haven't tried cloning, but see from some posts that doesn't work well either.
Terry
Re: Best way to include stack1 in another stack
Posted: Mon Mar 02, 2020 11:12 pm
by dunbarx
Hi.
Why do you have two stacks? Is one a "splash" stack that becomes the executable when making standalones?
As for getting code in one place, accessible from many other places, there are several techniques. These include creating library stacks, using behaviors, or sending certain scripts "to back". These all depend on what you want achieve.
Craig
Re: Best way to include stack1 in another stack
Posted: Tue Mar 03, 2020 12:58 am
by dntknwjck
Hi
Used two stacks to develop the calendar and interface. From previous platforms I have used I have been able to import things like this and assumed that to be the case with LiveCode. Appears I was wrong.
Can something like this be put in a library and be reused? If so can you point me to some place that has explanations and examples on how to build and use libraries.
Terry
Re: Best way to include stack1 in another stack
Posted: Tue Mar 03, 2020 2:50 am
by dunbarx
Used two stacks to develop the calendar and interface.
OK. Whatever. (and I am not being snarky)
assumed that to be the case with LiveCode. Appears I was wrong.
Certainly you can, though perhaps "import" is not the right term in the LC world.
Exploiting the message hierarchy is the principal native method to set up stacks that allow messages to "funnel" through them, usually "above" or "after" everything else contained in your app and its environs. You can also "insert" a single script, of any kind, "into back", where it, too, will receive messages after everything else does. Further, behaviors are supported in the quest to make LC more object oriented, and these are explicitly designated button or stack scripts that receive messages from other objects that point to them.
In short, yes, you can establish all the tools you need to do what you want.
A question at the most basic level. Do you know how to place, say, a "mouseUp" handler in the card script in such a way that any number of buttons on that card can use that handler? And that each of those buttons can be identified by the overarching handler so that each button can do its own thing?
Craig
Re: Best way to include stack1 in another stack
Posted: Tue Mar 03, 2020 11:22 am
by bogs
Heya Terry,
To answer what seems like your most likely way to go,
dntknwjck wrote: ↑Tue Mar 03, 2020 12:58 am
can you point me to some place that has explanations and examples on how to build and use libraries.
check
http://livecode.byu.edu/messages/libraries.php
I'm not sure why you wouldn't be able to just set your substack as it's own stack and issue a 'start using stack [your stack]' as you indicated in your first post, unless it was because it was a substack of another stack. Someone that knows better may be able to say for sure.
Re: Best way to include stack1 in another stack
Posted: Tue Mar 03, 2020 3:57 pm
by dntknwjck
Thanks Bogs, that was exactly what I was looking for.
Re: Best way to include stack1 in another stack
Posted: Tue Mar 03, 2020 4:45 pm
by dunbarx
Exploiting the message hierarchy is the principal native method to set up stacks that allow messages to "funnel" through them, usually "above" or "after" everything else contained in your app and its environs.
"Start using", as bogs explicitly mentioned, is how one does this. You can think of stacks "in use" as library stacks. These are placed near the very end of the hierarchy. But it is the hierarchy, and comfort in its use, that you simply must start practicing with.
For the other methods, you need to explore the "insert script" command, and then read a bit about behaviors:
http://lessons.livecode.com/m/4071/l/69 ... a-behavior
This and its related lessons...
Craig
Re: Best way to include stack1 in another stack
Posted: Tue Mar 03, 2020 6:50 pm
by AxWald
Hi,
Still a good example how to do it:
Sarah Reichelt's Calendar
Basically, your calendar is a separate stack. You call it:
Now you're in the Calendar stack, and when you're done selecting, do there:
Code: Select all
set the dialogdata to "whatEverYouWantToReturn"
close this window
Back at the caller stack, right after the first line at top, you:
Bingo.
Have fun!
Re: Best way to include stack1 in another stack
Posted: Tue Mar 03, 2020 9:04 pm
by bogs
Definitely worth looking at, nicely put together.
Re: Best way to include stack1 in another stack (DatePicker)
Posted: Thu Mar 05, 2020 5:04 pm
by dntknwjck
Thanks to all.
The information from AxWald was the final piece to make this work.
After I get things cleaned up I will post the code. It may be helpful to others.
DtPicker is a calendar Date Picker Example
I forgot how much fun it is to be a "Newbe"
Terry
DtPicker.zip posted 3/10/2020