TCollections.CreateList with Range of TArray<Variant>

68 views
Skip to first unread message

CompAdvantage

unread,
Jan 12, 2024, 2:07:29 PMJan 12
to Spring4D
I used to be able to create an IList of TArray<Variant> with the code:
TCollections.CreateList<TArray<Variant>>(Values)

That was with the build taken on 17 Apr 2023

However, the build I downloaded today raises an EVariantBadVarTypeError instead.

Unfortunately so much has changed in Spring.Collections.Lists that it hard to determine what the fix might be.  The final call in Spring4D code is 

          DynArrayAssign(target, source, typeInfo);

in the tkDynArray case of MoveManaged in the Spring unit.

The error message is:
 First chance exception at $00007FFED32FCF19. Exception class EVariantBadVarTypeError with message 'Invalid variant type'. Process SeleXpress3.exe (21312)

I hope this helps.

Stefan Glienke

unread,
Jan 12, 2024, 2:12:39 PMJan 12
to Spring4D
Without specifying what Values contains I am not able to answer this question

CompAdvantage

unread,
Jan 16, 2024, 5:59:58 AMJan 16
to Spring4D
Here is a sample application.  Note: this sample App doesn't raise an error at the same place as my original application, but examination of the newly created list indicates the issue has occurred:

program Project1;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils, System.Variants, Spring.Collections;

var
  items: IList<TArray<Variant>>;
  values: TArray<Variant>;
begin
  try
    values := [1];                                                // setting up a 1 element array of variant
    WriteLn('Number of elements in values: ', Length(values));
    items := TCollections.CreateList<TArray<Variant>>([values]);  // adding the values item as a range during construction
    WriteLn('item count: ', items.Count);
    WriteLn('Number of elements in item[0]', Length(items[0]));   // Error occurs here!

    items.ForEach(procedure (const item: TArray<Variant>)         // This call will also fail if the previous line is commented out
        begin
          WriteLn('Start of item');
          for var i in item do
            WriteLn(VarToStr(i));
          WriteLn('End of item');
        end);
    ReadLn;
    { TODO -oUser -cConsole Main : Insert code here }
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.


Stefan Glienke

unread,
Jan 16, 2024, 6:35:50 AMJan 16
to Spring4D
There indeed was an embarrassing bug in MoveManaged - fixed in develop

CompAdvantage

unread,
Jan 17, 2024, 7:11:19 AMJan 17
to Spring4D
I have merged your fix with my current version and tested it on both my test project and my original project - it's working 100%

Thanks for the quick response and precise solution.

Reply all
Reply to author
Forward
0 new messages