Something like that, but I'm starting to dislike this code more and more
Besides, I'm still confused as to why I get the array element type this way. I originally wrote it differently, but it didn't work...
And this worked, but I don't have time to figure it out yet, so I'll leave it as is
program Project1;
{$mode objfpc}{$H+}
{$M+}
{$RTTI EXPLICIT
PROPERTIES([vcPrivate,vcProtected,vcPublic,vcPublished])
FIELDS([vcPrivate,vcProtected,vcPublic,vcPublished])
METHODS([vcPrivate,vcProtected,vcPublic,vcPublished])}
uses
TypInfo;
type
TTest = record
A: array of Integer;
end;
var
T: TTest;
FieldTable: PExtendedFieldInfoTable;
FieldCount, I: Integer;
newlen: SizeInt = 33;
s: string;
ptd: PTypeData;
begin
T.A := [1, 2, 3];
FieldCount := GetFieldList(TypeInfo(TTest), FieldTable);
for I := 0 to FieldCount - 1 do
if FieldTable^[I]^.Name^ = 'A' then
begin
//How to get the array length?
WriteLn(DynArrayBounds(@PByte(@T)[FieldTable^[I]^.FieldOffset], FieldTable^[I]^.FieldType^)[0]+1);
//How to add another item to the array?
DynArraySetLength(PPointer(@PByte(@T)[FieldTable^[I]^.FieldOffset])^, FieldTable^[I]^.FieldType^, 1, @newlen);
WriteStr(s, FieldTable^[I]^.FieldType^^.Kind);
WriteLn(s);
case FieldTable^[I]^.FieldType^^.Kind of
tkUnknown:;
tkInteger:;
tkChar:;
tkEnumeration:;
tkFloat:;
tkSet:;
tkMethod:;
tkSString:;
tkLString:;
tkAString:;
tkWString:;
tkVariant:;
tkArray:;
tkRecord:;
tkInterface:;
tkClass:;
tkObject:;
tkWChar:;
tkBool:;
tkInt64:;
tkQWord:;
tkDynArray:
begin
ptd:=GetTypeData(FieldTable^[I]^.FieldType^);
case ptd^.OrdType of
otSLong: PInteger(PPointer(@PByte(@T)[FieldTable^[I]^.FieldOffset])^)[3]:=44;
end;
end;
tkInterfaceRaw:;
tkProcVar:;
tkUString:;
tkUChar:;
tkHelper:;
tkFile:;
tkClassRef:;
tkPointer:;
end;
end;
WriteLn(Length(T.A));
WriteLn(T.A[0]);
WriteLn(T.A[1]);
WriteLn(T.A[2]);
WriteLn(T.A[3]);
WriteLn(T.A[4]);
ReadLn;
end.