diff --git a/Src/Data/Myc.Data.POD.pas b/Src/Data/Myc.Data.POD.pas index 078d9ae..931c864 100644 --- a/Src/Data/Myc.Data.POD.pas +++ b/Src/Data/Myc.Data.POD.pas @@ -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; inline; + function GetItems(const Name: String): TScalar; property Def: TScalarRecordDefinition read GetDef; property Fields: TArray 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);