Welcome to the new DelphiDabbler Code Library Documentation.

This is a new site that's currently running on alpha code. There are going to be bugs. If you discover any, please report them on the site's issues page (GitHub account required). Thanks.

Warning: Many URLs are going to change. Refer to the README file to discover which library project's documentation has been completed.

DoFilter abstract method

Project: I/O Utility Classes

Unit: PJPipeFilters

Class: TPJPipeFilter

Applies to: ~>1.0

procedure DoFilter(const ValidData: TBytes); virtual; abstract;


Performs the filtering operation on given data. The action to be performed depends on the purpose of the filter. Descendant classes must override this method to perform the required filtering.

Data to be filtered is passed in the ValidData parameter. This byte array is guaranteed to contain only valid, processable data. Any “carry forward” bytes will have been trimmed from the array before passing to this method by trimming off the number of bytes returned from the LeftOverByteCount method.


Both TPJUnicodeBMPPipeFilter and TPJAnsiSBCSPipeFilter first convert the bytes of ValidData into text (Unicode in the former case and ANSI text in the latter).

They then trigger their respective OnText events to report the text that has just been read. Following that they parse the text into lines and trigger their OnLineEnd event for each line parsed. Any partial lines are carried forward until the next time the method is called.

Here is TPJAnsiSBCSPipeFilter’s implementation of the method:

procedure TPJAnsiSBCSPipeFilter.DoFilter(const ValidData: TBytes);
  Text: AnsiString;  // Text read from ValidData
  EOLPos: Integer;   // Position(s) of end of line marker in text
  // NOTE: code assumes SizeOf(AnsiChar) = 1
  // Record ANSI SBCS text
  SetLength(Text, Length(ValidData));
  Move(Pointer(ValidData)^, Pointer(Text)^, Length(ValidData));
  // Trigger OnText event for read text
  fPartialLine := fPartialLine + Text;
  // Break text into lines separated by EOLMarker, trigger OnLineEnd for each
  EOLPos := Pos(fEOLMarker, fPartialLine);
  while EOLPos > 0 do
    DoLineEnd(Copy(fPartialLine, 1, EOLPos - 1));
    fPartialLine := Copy(
      fPartialLine, EOLPos + Length(fEOLMarker), MaxInt
    EOLPos := Pos(fEOLMarker, fPartialLine);

fPartialLine stores text that is yet to be reported via the OnLineEnd event, DoLineEnd triggers the OnLineEnd event and DoText triggers the OnText event.