Used to determine if an object is Nil (no value).
expression = Nil
Nil means no value. When an object is first instantiated, it is automatically initialized to Nil. Some functions will return a Nil value under certain circumstances. FolderItem will return Nil if the user clicks the Cancel button when FolderItem presents the standard open file dialog box.
You can pass Nil for any of the string parameter types above (CString, PString, WString), but not for String. Passing Nil is not the same as passing the empty string, “”. Passing Nil means you want to pass a null pointer. Passing “” means you want to pass a non-null pointer to the representation of “” for the declared format.
If you try to access an object that has a Nil value, a NilObjectException error will be generated. If you don’t handle the exception, execution will stop. If you are testing the application in the IDE, you can choose Project > Break on Exceptions to halt execution whenever a runtime exception error occurs and open the Debugger.
If the code executes in a built application, the user will see a generic error message before the application quits.
This example uses Nil to determine if the user clicked the Cancel button in the standard open file dialog box presented by the FolderItem function.
Var f As FolderItem.ShowOpenFileDialog("") If f <> Nil Then // use the FolderItem End If
Var d As Dictionary Try d.Value("Name") = "Mary" Catch err As NilObjectException ErrorLabel.Text = err.Message End Try
All projects types on all supported operating systems.