Compatibility: 6.7.x and 6.8.x
The ability to check for nil pointers can be a critical technique for writing generic code. This tech tip discusses such an implementation.
I was working on an application that required that the records displayed in some, but not all, of the output forms be sorted. Since the output forms required the same coding, the code was placed in the project method Shell_OutputFormMethod. This method was called from the form method of each output form as explained below:
If records were to be sorted, a pointer to a column was passed:
If records were NOT to be sorted, a pointer to a column was NOT passed:
Note: The parenthesis must be used even if you are not passing the column pointer parameter, otherwise $1 will be undefined in Shell_OutputFormMethod causing an error.
As mentioned, the code for the output form was placed in the project method Shell_OutputFormMethod:
: (Form event=On Load )
: ($LFormEvent=On Close Detail )
The code of the subroutine Shell_ OrderRecordsByColumn was as follows:
ORDER BY(Shell_PointerToTableForField ($pDefaultSortField)->;$pDefaultSortField->;>)
Here is how this works:
RESOLVE POINTER returns a null string in the text variable $tVarName if no pointer has been passed to Shell_ OrderRecordsByColumn. We can then check for this null string and prevent the ORDER BY command from executing. This technique allows the generic Shell_OutputFormMethod to be used whether or not a column needs to be sorted for a specific output form.