Hi Servoy,
When a form with property namedFoundSet=DEFAULT is unloaded automatically by Servoy, it keeps its foundset state (loaded records and selected record)
When a form with property namedFoundSet=SEPARATE is unloaded automatically by Servoy, it loses its foundset state.
Is this a bug or the "designed" behavior? If this is the "designed" behavior, what is the reason behind it?
As far as we are concerned, the forms & their associated foundsets should keep their state regardless of the namedFoundSet property when Servoy automatically unloads them. When developers manually unload a form (by using history.removeForm) then the form foundset can be unloaded (if SEPARATE).
If Servoy cannot restore the state of something OR cannot provide the necessary means for the developers to restore that state, it should not unload forms and data! If there is some memory pressure or other condition in such cases - fire an event or throw an exception to notify the code and leave it up to the developers to decide what to do - do not just go behind our back and unload stuff.
With the current behavior we are facing a problem which cannot be resolved. Consider this:
1) the user opens 2 forms on 2 different tabs
2) in Form A (which has namedFoundSet=SEPARATE), the user loads data using a query similar to "load all records with status = Active"; this returns 50 records; the user then changes the status of 2 of those records to Inactive and saves the changes (however all 50 records remain visible in the grid); one of the records with Inactive status is currently selected;
3) the user switches to the other tab and performs some operations which trigger Servoy to unload Form A
4) the user then switches back to the tab with Form A.
Issue: currently, form A will show but it will be empty (no records will be displayed in the grid)
a) If we preserve the foundset query upon form unload and then use it to fetch the data back again on the re-load, only 48 records will be fetched AND there will be no way to "select" the inactive record (since it will not be included in the foundset)
b) if we preserve only the PK of the selected record, when the form is re-loaded we can load that record back, but the user expected 50 and not only 1 record
c) keeping the list of PKs of all loaded records is out of question (imagine if the result from the original query was 50000 and not just 50 records)
d) keep a reference to the whole foundset and then "load it back" in the form upon re-load - would love to do that IF there was some distinction in the form Unload event to let us know if it was triggered by our code (with history.removeForm) or by the Servoy automatic unload mechanism. Without that distinction however, we risk keeping in memory data which is not needed anymore. Unfortunately, the form Unload event does not tell us what invoked it. Now we have to do some nasty work-arounds and wrap the history.removeForm in our own "wrappers" just so we know in the form Unload event if we need to keep the form foundset or not, and if someone forgets to use the wrapper, we end up with a "memory leak".
In short - when the user switched to the second tab, he/she left Form A in one state and expected it to remain in that state, however we cannot restore that state no matter what we try. Using DEFAULT foundsets in our case is out of question because we need to be able to show multiple instances of the same form on multiple tabs.