Is there a way to detect (ie, via
{$IFOPT} or other?), and preferably to
disable, the
-CR compiler option for a block of code?
I've got a situation where a user has
-CR enabled, and some code (specifically, in Indy) is using object hard-casts (to utilize Delphi-style accessor classes to access
protected members in other units) which is being silently converted into the
as operator, which is breaking the code with
EInvalidCast errors at runtime.
For context:
https://forum.lazarus.freepascal.org/index.php/topic,63996.msg485641.html#msg485641Indy uses several accessor classes internally, and having
-CR silently create calls to the
as operator is going to wreak havoc with it. I never knew about this feature before. I'll have to start warning users not to compile Indy with
-CR enabled, but it would be nice to either fail the compile if
-CR is enabled, or be able to disable/restore
-CR dynamically with compiler directives on a case-by-case basis.