Previously, I talked about how the TDateTime triumvirate caused issues in runtime packages.
Today, I'll discuss why using implicit operators with TValue and the TDateTime triumvirate causes TValue to end up with the wrong type information.
TValue is a record that stores both a value and its associated PTypeInfo, allowing RTTI-based code to inspect types and values at runtime.
It exposes many implicit operators (e.g. from Integer, Double, TObject, TDateTime, TTime, etc.) so that assignments like V := Now; just work without explicitly calling a constructor.
However, when you compile with runtime packages and implicit operators are used across package boundaries, the compiler and linker must resolve which TValue.Implicit overload to call based on the static type as seen in that package. With the TDateTime triumvirate, however, type mangling issues can cause the wrong implicit overload to be picked, so the FTypeInfo stored in TValue no longer matches the logical type the caller expects. This happens due to the order in which the Windows DLL loader's resolves a symbol name. It might pick the TValue.Implicit(Value: TTime) overload instead of the correct TValue.Implicit(Value: TDateTime) when you call TValue.Implicit(Value), where Value: TDateTime, because the TDateTime triumvirate all resolves to the same mangled type name.
Instead of writing "var V: TDateTime := Now", or "var V := Now", consider using the TValue.From method instead, as follows:
TValue.From<TDateTime>(Now); TValue.From<TTime>(LTime); TValue.From<TDate>(LDate);
TValue.From is a generic routine that constructs a TValue using the generic type parameter T and its RTTI, rather than relying on overloaded implicit operators. The reason why this works, is that the compiler generates the code for TValue.From at the call site, so T is bound to the exact static type (e.g. TDateTime) as seen there, and TValue is created with TypeInfo(T) taken from that context. So, even when you use runtime packages, your code calls the correct TValue.From method, and sets the type information correctly.