Notification of need to refresh data

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Notification of need to refresh data

Post by phaworth » Tue Feb 23, 2010 3:59 am

I've come across several instances of the need to refresh the data I'm displaying on Card A due to something that happens on Card B, usually the addition/deletion/change of data in the SQLite database I'musing.

What I hope might be possible is a scheme whereby Card B can send out some sort of global message that will be picked up by any cards that care about the data on Card B. I guess I could send events to every card that needs to know of the changes but I'd like to make it generic enough that I don;t have to worry about changing the cod to add another send if I introduce another stack into my application.

It doesn't seem like the normal message path will handle this since once the message gets picked up by a card, and assuming the card passes it along, the message travels further up the message path which would exclude any other cards that need to know about it.

The other option would be for me to refresh all the data on a card every time it comes into focus but that doesn't seem very efficient.

Am I missing something obvious or can someone point me in the right direction please?

Thanks,
Pete

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4003
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Notification of need to refresh data

Post by bn » Tue Feb 23, 2010 10:26 am

Pete,
if I understand you correctly then you could set the custom property, lets say of the stack when you have changes on card B

Code: Select all

set the uCardBWasChanged of this stack to true
likewise you could set a global variable to true.
On preopencard you could do your update of card A.
If you have many different cards that are visited with different frequency then you could put a timestamp into your "the uCardBWasChanged of this stack"
Card A,C,D would check a custom property of their own which stores the last update they did

Code: Select all

on preopencard
if the uIDidUpdate of this card <> the uCardBWasChanged of this stack then
do you update
set the uIDidUpdate of this card to the uCardBWasChanged of this stack
end preopencard
This avoids unnecessary updates.
Otherwise you would have to go for a broadcasting system in which all cards/controls in need of update would be registered and the update is triggered with one command
regards
Bernd

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Re: Notification of need to refresh data

Post by phaworth » Tue Feb 23, 2010 6:44 pm

Thanks Bernd. As well as when a card is opened, I need to do this when an already opened card (Card A) receives focus after the user has been working on another card (Card B). Your solution will still work though, looks like the resumeStack event would be the place to put the code.

Your mention of a broadcast system is interesting to me as well. Have you implemented such a thing? It sounds like you're suggesting some sort of central repository where objects could register their interest in certain events, coupled with a command that would go through that registry looking for a specific event type and send a message to every object?

Thanks,
Pete

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4003
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Notification of need to refresh data

Post by bn » Tue Feb 23, 2010 7:40 pm

phaworth wrote:Your mention of a broadcast system is interesting to me as well. Have you implemented such a thing?
No, I have not implemented such a system. I just read that the GLX framework has such a mechanism. http://www.bluemangolearning.com/revolu ... framework/ But one could think of a way to implement that. The central repository of receivers could be a custom property of the stack. You put the e.g. the long id of all receivers into a list in that property.
Than there would be a handler that is triggered by the sending object, your card B for example.
The handler would use the custom property and sends an update command to all receivers, which of course need a script to handle the update command and initialise the update.
Sounds a little complicated but should be feasible.
regards
Bernd

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4003
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Notification of need to refresh data

Post by bn » Tue Feb 23, 2010 7:47 pm

phaworth wrote: looks like the resumeStack event would be the place to put the code.
Pete, you could trap the resumeStack and issue a preopencard message

Code: Select all

on resumeStack
  send preopencard to the current card
  pass resumeStack -- just in case
end resumeStack
depending on the structure of your stack you might not always get a resumstack message, but most likely a preopencard/opencard message.
regards
Bernd

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”