Reputation: 169
how i can pass memo lines strings to TRecords
fields to use theme as a parameters for idHTTP POST methode?
usually id do it like this
for i := 0 to Memo1.Lines.Count-1 do
begin
P := Pos('+', Memo1.Lines.Strings[i]);
Email:= Copy(Memo2.Lines.Strings[i], 1, P-1);
Name:= ExtractName(Memo2.Lines.Strings[i]);
lPOSt // HTTP POST; //Email&Name Global Var for HTTP post Params
Sleep(1000);
end;
but in pipeline pattern i have to use records , so i can pass the parameters to the queue. Or is there any way to use Email
and Name
as parameters for for POST method?
Reply := TStringList.Create;
Params.Add('Email=' + Email); // Email is Global Var
Params.Add('Name=' + Name); // Name is Global Var
lHTTP.Post('http://www.mywebserverx.com/', Params);
type
TRecords = record
Name : string;
eMail : string;
Car: string;
end;
My pipeline code, using HTTP Get
procedure TForm2.StartButtonClick(Sender: TObject);
var
s : string;
urlList : TStrings;
begin
urlList := Memo1.Lines;
pipeline := Parallel.Pipeline;
pipeline.Stage(Retriever).NumTasks(10).Run;
// Retriever>>>idHTTP GET opertaion
//how to modify the pipeline input after using records as Params?
for s in urlList do
pipeline.Input.Add(s);
pipeline.Input.CompleteAdding;
any help is appreciated.
Upvotes: 1
Views: 152
Reputation: 2815
pipeline.Input
is of type IOmniBlockingCollection
. Method IOmniBlockingCollection.Add
expects a parameter of type TOmniValue
. For most types you can simply put the variable as the parameter because TOmniValue
implements many implicit class operators. These implicit class operators do all the work for you, when the variable is not of type TOmniValue
.
However, TOmniValue
does not implement a implicit class operator for records. For record types, you have to cast it to TOmniValue
yourself. Fortunately, TOmniValue
has a generic class function for this: TOmniValue.CastFrom<T>()
.
So, if you want to add a record of type TRecords
(which is a bad, ambigous name, imho) you just call pipeline.Input.Add(TOmniValue.CastFrom<TRecords>(RecordsVar)
.
But why do you want to do all the parsing in the calling thread?
The calling thread should just add the strings like it is currently implemented:
for s in urlList do
pipeline.Input.Add(s);
pipeline.Input.CompleteAdding;
Let the parsing happen in the pipeline. There you can use implicit casting from TOmniValue
to string
.
Upvotes: 1