我正在尝试将Delphi2005代码转换为Delphi Tokyo 10.2.3代码。不再识别函数VarType。我需要函数VarType来确定变量变量的基本类型。总的来说,根据许多帖子,我发现它应该在System.variants单元中。但是,如果我搜索例如在:
它不在这个单元中。此外,我找不到单位变体,只有单位变体。但是,使用单位变量我得到一个运行时错误:必要的记录,对象或类类型。所以这不起作用。
if (System.Variant.VarType(Value) and varTypeMask) =
System.Variant.varString then // VarType(Value) unbekannt
begin
TByte8Array(PRecFORMULA3(PBuf).Value)[0] := 0;
end;
无论如何,我在System.variant中找不到varType。变种不再存在了吗?
谁能帮我??
您链接的文档很旧。这是为了引入Unit Scope Names之前的Delphi 2009。但即使在那个旧的文档中,VarType()
is documented as being in the Variants
unit(不在Variant
单元中,也不存在)。
单位范围名称,如System
,被添加到XE2中的RTL / VCL单位名称(因此,Variants
单位变为System.Variants
)。
Embarcadero的新版DocWiki取代了旧的Docs网站,清楚地显示了VarType()
function is indeed located in the System.Variants
unit。
确保:
System.Variants
条款中有uses
:
uses
..., System.Variants;
System
,然后您可以在Variants
子句中使用uses
:
uses
..., Variants;
无论哪种方式,您都可以按预期使用VarType()
,而无需完全限定它:
if (VarType(Value) and varTypeMask) = varString then
begin
TByte8Array(PRecFORMULA3(PBuf).Value)[0] := 0;
end;