Thanks.This version is easier to understand to me.I see it as if data( const array of const) is make up of 'Variant' type.
Quote from: PeterHu on November 09, 2025, 03:56:26 amThanks.This version is easier to understand to me.I see it as if data( const array of const) is make up of 'Variant' type.array of const is different from Variant. While both rely on the concept of variant records, array of const is based on TVarRec and does not provide operators. It's only really intended for parameter passing, while Variant has a much wider scope due to functionality like late binding and provided operator overloads.
Yes, code using Variants looks even neaterCode: Pascal [Select][+][-]program app;{$mode objfpc}//{$codepage utf8}{$modeswitch advancedrecords}{$h+} uses gvector; type TFruit = record name: String; color: Integer; class operator :=(const data: array of Variant): TFruit; end; class operator TFruit.:=(const data: array of Variant): TFruit;begin Result.name:=data[0]; Result.color:=data[1];end; procedure print(s: String);begin WriteLn(s);end; var V: Variant; // It is necessary due to a bug https://gitlab.com/freepascal.org/fpc/source/-/issues/41492 begin with (specialize TVector<TFruit>.Create) do begin pushback(['apple', 1]); WriteLn(items[0].name); Free; end; print('apple'); ReadLn;end.