update of documentation for $OBJECTCHECKS and -CR compiler option
Reading the documentation (https://www.freepascal.org/docs-html/prog/progsu57.html):
Reading the documentation (https://www.freepascal.org/docs-html/prog/progsu57.html):
1.2.57 $OBJECTCHECKS : Check Object
This boolean switch determines whether code to test the SELF pointer is inserted in methods. By default it is OFF. For example:
{$OBJECTCHECKS ON}
If the SELF pointer is NIL a run-time error 210 (range check) will be generated.
This switch is also activated by the -CR command line option.
Also in https://www.freepascal.org/docs-html/user/usersu15.htm the -CR option is described:
-CR
Generate checks when calling methods to verify if the virtual method table for that object is valid.
As stated by PascalDragon here: https://forum.lazarus.freepascal.org/index.php/topic,58944.msg439261.html#msg439261 {$OBJECTCHECKS ON}, the above switch will not only test if a pointer is NIL but it will force FPC to complain about typecasting during runtime. and here: https://forum.lazarus.freepascal.org/index.php/topic,58944.msg439395.html#msg439395 The -CR switch enables $OBJECTCHECKS as well as $RANGECHECKS checking also if a pointer is nil and if it is inside the allowed range
As the above switch (-CR) exist in the Debug section of Lazarus, please correct the above part of the documentation, since they can cause misunderstanding from the exception raised due to use of the above switches.