KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Loading and Unloading Records
PRODUCT: 4D | VERSION: 16 | PLATFORM: Mac & Win
Published On: November 28, 2017

When performing an action such as grabbing all the records from a table using the ALL RECORDS command, something that may not be obvious is that the first record from that related table is automatically loaded as the first record.

This means that it is unnecessary to call FIRST RECORD or LOAD RECORD after running this command. Given this behavior, it is possible to reduce the viscosity of the code by removing the unnecessary calls.

For example, the code:



Can be written with less viscosity as:



This can be confirmed by checking in the debugger and noticing that the record loaded is the first record in the table.



The same is true for the other query commands like QUERY, QUERY SELECTION, and QUERY BY FORMULA, they will load the first record automatically.

Another thing to keep in mind is unloading a record when that record is not being used. Since a record will be locked when it is loaded, unloading a record is important to allow other processes or users to modify that record.

Something that is common is to loop through the records in a table using a for loop and the NEXT RECORD command. What may not be obvious is that this command will automatically unload the record, so it is not necessary to manually unload the record with the UNLOAD RECORD command.

For example, the code:



Can be written with less viscosity as:



Again, this can be verified by using the debugger and noting that while stepping through the loop, there is always only one locked record since the NEXT RECORD command unloads the current record automatically.



The same is also true of commands PREVIOUS RECORD and LAST RECORD, they will automatically unload the record and so do not need to be coupled with UNLOAD RECORD when being used.