Delphi 11.2.3:Delphi中的函数VarType()在哪里?

问题描述 投票:-1回答:1

我正在尝试将Delphi2005代码转换为Delphi Tokyo 10.2.3代码。不再识别函数VarType。我需要函数VarType来确定变量变量的基本类型。总的来说,根据许多帖子,我发现它应该在System.variants单元中。但是,如果我搜索例如在:

http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/!!FUNCTIONS_System.html

它不在这个单元中。此外,我找不到单位变体,只有单位变体。但是,使用单位变量我得到一个运行时错误:必要的记录,对象或类类型。所以这不起作用。

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。变种不再存在了吗?

谁能帮我??

variant delphi-10.2-tokyo
1个回答
0
投票

您链接的文档很旧。这是为了引入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

确保:

  1. 你的System.Variants条款中有usesuses ..., System.Variants;
  2. 您在项目的单位范围名称列表中有System,然后您可以在Variants子句中使用usesuses ..., Variants;

无论哪种方式,您都可以按预期使用VarType(),而无需完全限定它:

if (VarType(Value) and varTypeMask) = varString then
begin
  TByte8Array(PRecFORMULA3(PBuf).Value)[0] := 0;
end;
© www.soinside.com 2019 - 2024. All rights reserved.