The runtime error checking of type casts in the debugging dialog.
Says this is a bad typecast.
LScheduler := TIdYarnOfThreadAccess(FYarn).FScheduler;
It is a perfectly fine typecast in this context.
FYarn is a pointer to a
TIdYarn object.
TIdYarnOfThread derives from
TIdYarn, and
TIdYarnOfThreadAccess derives from
TIdYarnOfThread.
FScheduler is a
protected member of
TIdYarnOfThread, hence the use of an accessor class to reach it. This works perfectly fine, is a pretty common practice in Delphi, and there are quite a number of similar accessor classes used in Indy.
Is this the
-CR (Verify method calls) compiler option at work? From what I've read elsewhere, that option can actually silently convert an object hard-cast into a call to the
as operator, which would be very bad in this case, since the
as operator is not compatible with accessor classes.
FYarn does not point at an object which actually derives from
TIdYarnOfThreadAccess, so the
as operator will fail such a cast. An accessor is just meant to bring
protected members into scope of the calling unit. This silent behavior would break every other accessor class being used in Indy. That compiler option needs to be disabled if it is enabled. I'll have to see if there is a way to detect/disable it in code.