TValue
not intended to arbitrarily manipulate its contents (it would have more helpers, for example, when setting record fields, etc.), but rather to transfer values ββbetween specific static types and dynamic RTTI. In this regard, TValue.SetArrayElement
is an anomaly, and looking back might not be included. However, you may ask:
uses Rtti; type TMyArray = array of Integer; TMyClass = class function Go: TMyArray; end; function TMyClass.Go: TMyArray; var i: Integer; begin SetLength(Result, 5); for i := 0 to 4 do Result[i] := 3; end; procedure P; var ctx: TRttiContext; v: TValue; len: Longint; i: Integer; begin v := ctx.GetType(TMyClass).GetMethod('Go').Invoke(TMyClass.Create, []); Writeln(v.ToString); len := 10; DynArraySetLength(PPointer(v.GetReferenceToRawData)^, v.TypeInfo, 1, @len); Writeln(v.GetArrayLength); for i := 0 to v.GetArrayLength - 1 do Writeln(v.GetArrayElement(i).ToString); end; begin P; end.
source share