1

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.

Thunderx
  • 169
  • 1
  • 9
  • Your question is a bit unclear to me. Do you want to add `TRecords` to the pipeline? What should happen in the pipeline? Maybe you should add more information and/or a more complete example. I answered your question anyway as I understood it for now. – René Hoffmann Aug 30 '16 at 08:59
  • @RenéHoffmann Edited the post, i have memo contains `email+name` strings i want use these strings as parameters in my post method, i usually separate the Email and Name using functions – Thunderx Aug 30 '16 at 10:05
  • @RenéHoffmann have a look here [http://stackoverflow.com/questions/39439950/how-to-take-the-input-string-to-the-output-of-pipeline-pattern] – Thunderx Sep 13 '16 at 17:47

1 Answers1

1

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.

René Hoffmann
  • 2,766
  • 2
  • 20
  • 43