PatV 1 Posted September 4, 2019 (edited) Delphi 10.3 Omnithead 3.07.5 Hi All here is a definition of an array of .. TpDataType = (dtNone, dtInteger, dtDateTime, dtString, dtBlob); rParameter = record Field : string; Value : Variant; AsValue : TpDataType; end; TParameters = array of rParameter; I would like to pass it to a worker as parameter, so CreateTask(Worker) .MonitorWith(OTLMonitor) .SetParameter('Params',TOmniValue.Create([Params]); I've tried also .SetParameter('Params',TOmniValue.FromArray<TParameters>(Params)) and convert it again like function TConnectionPoolData.WithParameters(const aValue : TOmniValue) : IConnectionPoolData; begin FParams := aValue.CastTo<TParameters>; Result:=Self; end; But it's not working as expected, as I'm getting bunch of data Do I need to use a class instead ? Thanks Patrick Edited September 4, 2019 by PatV add omnithread version Share this post Link to post
Primož Gabrijelčič 223 Posted September 4, 2019 This works: program Project191; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils, OtlCommon; type TpDataType = (dtNone, dtInteger, dtDateTime, dtString, dtBlob); rParameter= record Field : string; Value : Variant; AsValue : TpDataType; end; TParameters = TArray<rParameter>; var params, params2: TParameters; ov: TOmniValue; begin SetLength(params, 2); params[0].Field := 'a'; params[0].Value := 1; params[0].AsValue := dtInteger; params[1].Field := 'b'; params[1].Value := Now; params[1].AsValue := dtDateTime; ov := TOmniValue.FromArray<rParameter>(params); params2 := ov.ToArray<rParameter>; end. You will have to convert 'array of rParameter' to 'TArray<rParameter>'. TOmniValue has special support (FromArray, ToArray) for the latter but not for the former. Share this post Link to post
PatV 1 Posted September 4, 2019 Thanks a lot Primož, it helps me a lot. And thanks for sharing Omnithread Patrick Share this post Link to post