detect cache

Questions, answers, tips and ideas on Servoy Client

detect cache

Postby david » Wed Jul 02, 2008 2:54 am

Is there a way to detect if a form is in memory? a record in memory?

I'd like to trigger a visual "loading..." type of thing if a form or a record are not in memory.

Depending on how much a form/record is loaded up with stuff, the time difference between navigating to an in memory vs not in memory can be dramatic.
David Workman, Kabootit

Image
Everything you need to build great apps with Servoy
User avatar
david
 
Posts: 1727
Joined: Thu Apr 24, 2003 4:18 pm
Location: Washington, D.C.

Postby david » Wed Jul 02, 2008 6:17 pm

I think the following bits of code will do the trick. Still needs a bit of testing.

This code attaches a form property called "hit" to make the distinction (note that "hit" is not a field name). Attach to form onShow event:

Code: Select all
// track if a form is hit for the first time
// attach to form onShow event

var form = currentcontroller.getName()

if (forms[form].hit) {
   plugins.dialogs.showInfoDialog("", "Repeat form", "OK")
}
else {
   forms[form].hit = true
   plugins.dialogs.showInfoDialog("", "1st form", "OK")
}


Need to create an unstored calc called "touched" and containing "//return 1" for this code to work. Attach to form onRecordSelection event:

Code: Select all
// track if a record is hit for the first time
// attach to form onRecordSelection event

var form = currentcontroller.getName()
var record = forms[form].foundset.getRecord(currentcontroller.getSelectedIndex())

if (record.touched) {
   plugins.dialogs.showInfoDialog("", "Repeat record", "OK")
}
else {
   record.touched = 1
   plugins.dialogs.showInfoDialog("", "1st record", "OK")
}
David Workman, Kabootit

Image
Everything you need to build great apps with Servoy
User avatar
david
 
Posts: 1727
Joined: Thu Apr 24, 2003 4:18 pm
Location: Washington, D.C.

Postby pbakker » Thu Jul 03, 2008 9:08 am

You can check the forms[] to see if a form is loaded. The forms[] only has entries in it for actually loaded forms (contrary to the Array the allNames property on the forms node returns, which contains all forms).

The code below allows you to check the existance of a formName in the forms Array without actually loading it into it:
Code: Select all
application.output(forms.length);
if ('myFormName2Check' in forms) {
   application.output('true')
} else {
   application.output('false')
}
application.output(forms.length);

Also, you know about arguments[0] for an onShow event being true of false, depending if the form is shown for the first time, right?

Do note that the onShow event is not the right place to check, because when you touch a form in scripting, it's already loaded (onLoad is fired), but the actual showing of the form can happen at a completely different time (depending when you actually show it).

Determining of a record is already loaded into or not is really doable, I think. Maybe foundset.selectRecord() could work for you, because it only returns true if the record was actually selected and it only is able to select the record if the record is already in memory.
pbakker
 
Posts: 2822
Joined: Wed Oct 01, 2003 8:12 pm
Location: Amsterdam, the Netherlands

Postby david » Wed Jul 09, 2008 12:25 am

Thanks Paul. A couple things that I didn't know.

The forms[] object has some interesting characteristics. Besides working great for detecting initial form load I think we'll use it for a few other things.

We did figure out a first record load approach without having to create an unstored calc for each table. But it only works in the context of our frameworks where all the record navigation is handled a level higher than the workflow forms. So not something that can easily be applied to other situations. (Maybe Servoy can add a recordLoaded() function that doesn't actually load the record. If a record has a lot of related data that gets pulled in when it loads it can take a bit of time to get all that into memory.)

The ability to give user feedback (we give the option to turn on the busy cursor and/or show a static progress bar with custom label) for initial form and record loads is quite nice. Configurable per navigation item so you can turn on or off depending on performance.

Goes a long ways in fixing one of our most prominent complaints: users don't like staring at nothing -- even for a second!
David Workman, Kabootit

Image
Everything you need to build great apps with Servoy
User avatar
david
 
Posts: 1727
Joined: Thu Apr 24, 2003 4:18 pm
Location: Washington, D.C.


Return to Servoy Client

Who is online

Users browsing this forum: No registered users and 17 guests