This commit is contained in:
Michael Schimmel
2025-08-28 14:21:15 +02:00
parent 77d2cb3f92
commit 6fcf8c26c8
+24 -11
View File
@@ -27,7 +27,6 @@ type
);
TScalarBytes = array[0..15] of Byte;
TScalarPChar = array[0..7] of Char;
TScalarString = String[15];
@@ -186,9 +185,11 @@ type
function GetDef: TScalarRecordDefinition; inline;
function GetFields: TArray<TScalarValue>; inline;
function GetItems(const Name: String): TScalar;
property Def: TScalarRecordDefinition read GetDef;
property Fields: TArray<TScalarValue> read GetFields;
property Items[const Name: String]: TScalar read GetItems; default;
strict private
FDef: TScalarRecordDefinition;
@@ -222,17 +223,8 @@ begin
end;
class function TScalarValue.FromBytes(const AValue: TScalarBytes): TScalarValue;
var
len: Integer;
begin
FillChar(Result.FBytes, SizeOf(Result.FBytes), 0);
len := Length(AValue);
if (len > 0) then
begin
if (len > SizeOf(Result.FBytes)) then
len := SizeOf(Result.FBytes);
Move(AValue[0], Result.FBytes[0], len);
end;
Result.FBytes := AValue;
end;
class function TScalarValue.FromChar(AValue: Char): TScalarValue;
@@ -538,6 +530,27 @@ begin
Result := FFields;
end;
function TScalarRecord.GetItems(const Name: String): TScalar;
var
i: Integer;
fieldDef: TScalarRecordField;
begin
// Find the index of the field by name (case-insensitive)
for i := 0 to Length(FDef.Fields) - 1 do
begin
fieldDef := FDef.Fields[i];
if (CompareText(fieldDef.Name, Name) = 0) then
begin
// Found it. Construct the TScalar result from the kind and value.
Result.Create(fieldDef.Kind, FFields[i]);
exit;
end;
end;
// If we get here, the field was not found.
raise EArgumentException.CreateFmt('Field "%s" not found in record definition.', [Name]);
end;
{ TScalarSeries }
constructor TScalarSeries.Create(AKind: TScalarKind; const AItems: TSeries<TScalarValue>);