这是一个片段,展示了我想要实现的目标:
type
TMyObject<T> = class (TObject)
function GetVarType(Value: T): TVarType;
end;
function TMyObject<T>.GetVarType(Value: T): TVarType;
var
TmpValue: Variant;
begin
TmpValue := Variant(Value); //Invalid typecast
Result := VarType(TmpValue);
end;
我知道使用类型转换的方法是天真的,但我希望您能理解我的想法。我想用一些转换机制来替换它。
TMyObject始终是简单类型,如Integer、String、Single、Double。
这种转换的目的是让函数VarType为每种简单类型给出整数常量,我可以将其存储在其他地方。
我想知道是否可能进行这种转换?
感谢您的时间。