The Compiler allows me to access a Variant.Vtype at compile time with no issues, however, at runtime I get an error?It doesn't know. For compatibility with Delphi, the dispatching interface is supported and any valid identifiers are allowed. I. e. at compile time this code will allowed
If SomeVariant.Vtype = 0 Then Beep;
Instead I have to cast it.
If TVarData(V).VType = 0...…
Why do I need to do this if the compiler knows about the field at compile time?
Shouldn't the compiler flag a warning here?No. Variant type was invented for such purposes. If you need more strict validation, try not to use variables of this type.
So the compiler is treating the variant as a interface call, I thought that only for the OleVariant?The difference between Variant and OleVariant is that the latter only allows types that are supported by Microsoft's OLE while the former also supports Object Pascal specific types (though not necessarily all).
while [Variant] also supports Object Pascal specific types