In Delphi XE8, I am trying to pass an array to the OTL task in SetParameter
from OmniThreadLibrary:
implementation
type
TCookie = record
Name: string;
Value: string;
ExpDate: string;
ModDate: string;
end;
TCookieArray = array of TCookie;
var
CurCookies: TCookieArray;
procedure TForm1.btnStartTaskClick(Sender: TObject);
begin
SetLength(CurCookies, 2);
CurCookies[0].Name := 'username';
CurCookies[0].Value := 'Paul';
CurCookies[1].Name := 'password';
CurCookies[1].Value := 'none';
FGetCookieDetailsTask := CreateTask(GetCookieEntries, 'GetCookieEntries')
.MonitorWith(OTLMonitor)
// Compiler complaint:
.SetParameter('CookiesArray', TOmniValue.FromArray<TCookieArray>(CurCookies))
.Run;
end;
The compiler complains about the SetParameter line:
[dcc32 Error] Unit1.pas(310): E2010 Incompatible types:
'System.TArray<Unit1.TCookieArray>' and 'TCookieArray'
Unfortunately, there are no examples in the OTL book on how to use FromArray
in SetParameter
to pass an array to the task.
So how can this be done?
EDIT: ba__friend asked that I show the source code from my solution in the comments of his answer:
FGetCookieDetailsTask := CreateTask(GetCookieEntries, 'GetCookieEntries')
.MonitorWith(OTLMonitor)
// Now no compiler complaint:
.SetParameter('CookiesArray', CurCookies)
.Run;
procedure GetCookieEntries(const task: IOmniTask);
var
TaskCookies, HostCookies: TCookieArray;
begin
HostCookies := task.Param['CookiesArray'];
TaskCookies := Copy(HostCookies, 0, Length(HostCookies));