Home > Software engineering >  How did String.Split change in Delphi Tokyo?
How did String.Split change in Delphi Tokyo?

Time:02-25

The following code example will compile in Delphi XE5 to Seattle (10.0). In Delphi Tokyo (10.2) I get a compile error on the ExcludeEmpty parameter (E2003 Undeclared identifier: 'ExcludeEmpty').

What is going wrong?

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils;
  var S : String ;
      SA : Tarray<String> ;
begin
  S := '1234 5678' ;
  SA := S.Split([' '], ExcludeEmpty)
end.

CodePudding user response:

This is an old enum and the values (None, ExcludeEmpty, ExcludeLastEmpty) do not have prefixes like newer enums to avoid identifier collisions. Compiling with {$SCOPEDENUMS ON} forces the use of a scope to prevent issues with collisions.

 SA := S.Split([' '], TStringSplitOptions.ExcludeEmpty);

I don't know all of the versions of Delphi that use this option to compile this enum but Delphi 11 does.

  • Related