0

I am trying to convert Delphi2005 code to Delphi Tokyo 10.2.3 code. The function VarType is no longer recognized. I need the function VarType to determine the basic type of a variant variable. In general I find, according to many postings, that it should be in the unit System.Variants. However, if I search e.g. in:

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

It is not in this unit. Furthermore, I cannot find the unit variants, only a unit variant. However, using the unit variant I get a runtime error:

Record, object or class type necessary

. So this doesn't work.

if (System.Variant.VarType(Value)  and varTypeMask) =         
   System.Variant.varString  then  // VarType(Value) unbekannt
begin
  TByte8Array(PRecFORMULA3(PBuf).Value)[0] := 0;
end;

Anyway I don't find VarType in System.variant. Does variants not exist anymore?

Can anyone help me?

Mike Torrettinni
  • 1,816
  • 2
  • 17
  • 47
  • Very muddled. You link to documentation for Delphi 2009, which you certainly aren't using. You refer to Delphi 11, which does not exist. You tag the question XE (the version between 2010 and XE2) which again I don't believe you are using. There is no RTL unit named `System.Variant`. A bit more care is needed here. Details matter, and it pays to know what software you are using. – David Heffernan Sep 05 '18 at 15:56
  • Hello, thanks very much for your comment. Sorry, it is Delphi 10 and I thought that the problem should be the same for the XE version of Delphi. I didn't see that the link was for Delphi2009 and just wondered why there is one home page with so many entries and without the possibility (visible to me) to distinguish to which Delphi version it belongs, e.g. by filter or some thing like this, if they are so different – Thommy 7571 Sep 06 '18 at 06:14
  • Please edit the question to resolve all of these problems. Thank you. – David Heffernan Sep 06 '18 at 06:17

1 Answers1

1

The documentation you linked to is quite old. It is for Delphi 2009, which predates the introduction of Unit Scope Names. But even in that old documentation, VarType() is documented as being in the Variants unit (not in the Variant unit, which does not exist).

Unit Scope Names, like System, were added to RTL/VCL unit names in XE2 (thus, the Variants unit became System.Variants).

Embarcadero's newer DocWiki, which replaces the old Docs site, clearly shows that the VarType() function is indeed located in the System.Variants unit.

Make sure that either:

  1. you have System.Variants in your uses clause:

    uses
      ..., System.Variants;
    
  2. you have System in your project's list of Unit Scope Names, and then you can use Variants in your uses clause:

    uses
      ..., Variants;
    

Either way, you can then use VarType() as expected, without having to fully qualify it:

if (VarType(Value) and varTypeMask) = varString then
begin
  TByte8Array(PRecFORMULA3(PBuf).Value)[0] := 0;
end;
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • Hello,Thanks for your answer, in deed you are right. Originally, there was System in the uses list, but since it was needed for a special problem I specified System.UITypes . I did not see that it was used for other methods too. Furthermore there was variants in the uses list but only specified for the version 5.0 of Delphi... Finally when I typed "System.variants." before varTypes I was told that "there is no unit unit variants in System". I only got no error at design time using variant .. So I was confused. After deleting the version option (5.0) I got it compiled!! – Thommy 7571 Sep 06 '18 at 06:40
  • by the way should a method present in System.SysUtils not be found if I put System in uses? It seems that it is not the case... – Thommy 7571 Sep 06 '18 at 07:08
  • @Thommy7571 `System`, `System.SysUtils`, `System.Variants`, these are all different units. You can't use something from a unit if that unit is not in the `uses` clause (the `System` unit is implicit). It is not enough to just have `System` specified alone. And there is also a difference between the actual `System` unit and the `System` unit scope name. – Remy Lebeau Sep 06 '18 at 14:01