How To…Use Bookmarks With TextPipeline

Question

“How can I use the TextPipeline to print only specific records or apply a filter?”

Solution

This example shows how to add a list of Bookmarks to the TextPipeline to control which records print.

All DataPipelines support bookmarking and bookmark list data traveral. When bookmarks are added to a datapipeline, it will traverse only the bookmark records. The Bookmark list acts as an index/filter for the data. This technique can be used with any type of DataPipeline.

Download: TextPipeBookmarkTraversal.zip

Sample Delphi code:

procedure TForm1.FormCreate(Sender: TObject);
var
  liIndex: Integer;
begin

  {assign the file name (ex. current directory + dm0133.txt)}
  ppTextPipeline1.FileName := ExtractFilePath(ParamStr(0)) + 'dm0133.txt';

  FBookmarks := TList.Create;

  BuildBookmarkList;

  {apply bookmarks for datapipeline}
  for liIndex := 0 to FBookmarks.Count-1 do
    ppTextPipeline1.AddBookmark(Integer(FBookmarks[liIndex]));

end;

procedure TForm1.BuildBookmarkList;
var
  liIndex: Integer;
begin

  ppTextPipeline1.Open;
  ppTextPipeline1.First;

  liIndex := 0;

  {bookmark every fourth record}
  while not(ppTextPipeline1.EOF) do
    begin
      Inc(liIndex);

      if (liIndex mod 4) = 0 then
        FBookmarks.Add(Pointer(ppTextPipeline1.GetBookmark));

      ppTextPipeline1.Next;
    end;

end;


procedure TForm1.Button1Click(Sender: TObject);
begin
  ppReport1.Print;
end;