procedure TMainForm.DrawGrid1DrawCell(Sender: TObject; Col, Row: Longint;
  Rect: TRect; State: TGridDrawState);
var
  TheText: string[16];
  i: Integer;
  byteArray: Array[0..15] of Byte;
  lBytesRead: Longint;
  aOffset, dummyLargeint: ULargeint;
begin
  begin

    { Calculate byte offset into Stream and seek to that byte position }
    aOffset := Row shl 4;
    if SUCCEEDEDHR(m_pStream.Seek(aOffset, Longint(STREAM_SEEK_SET), dummyLargeint)) then
      begin
      if SUCCEEDEDHR(m_pStream.Read(@byteArray, 16, lBytesRead)) then begin

        { xxxxxxxx: xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx  abcdefghijklmnopq }
        TheText := IntToHex(Row shl 4, 6) + ':' ;
        SetBkColor(DrawGrid1.Canvas.Handle, GetSysColor(COLOR_WINDOW));
        DrawGrid1.Canvas.TextOut(Rect.Left + 2 * m_iCharWidth, Rect.Top, TheText);

        for i := 0 to lBytesRead - 1 do begin
          TheText := IntToHex(byteArray[i], 2);
          DrawGrid1.Canvas.TextOut(Rect.Left + 10 * m_iCharWidth + m_iCharWidth * i * 3
            , Rect.Top, TheText);
        end;

        { Format output string as printable characters or '.' if not printable }
        TheText := '';
        for i := 0 to lBytesRead - 1 do
          if IsCharAlphaNumeric(Char(byteArray[i])) then
            TheText := TheText + Char(byteArray[i])
          else
            TheText := TheText + '.';

        DrawGrid1.Canvas.TextOut(Rect.Left + 60 * m_iCharWidth, Rect.Top, TheText);
      end;
    end;
  end;
end;
Figure 11: Implementation of the Owner-Draw Grid

