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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
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; |