I can't see content of the memo field in DBGrid

Quote
----- Original Message -----
From: "Goran" <gesi...@verat.net>
Subject: I can't see content of the memo field in DBGrid
> I have DBGrid with custom table on my form, but I can't see
> content of the memo field. I see only text (MEMO) in each row.

Goran,
I have read this somewhere and it worked for me. Write a OnDrawColumnCell
routine like this:

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn;
  State: TGridDrawState);
begin
  If Column.FieldName = 'MyMemoField' then          // replace with your
field name
    DrawMemoCell( Sender, Rect, Query1, 'MyMemoField');
end;

procedure TForm1.DrawMemoCell( Sender: TObject; const Rect: TRect;
                       xTable: TQuery; cField: string );
var
 cChars  : array [0..501] of char;   {array size is number of characters
needed}
 xBlob   : TBlobStream;              {from the memo field}
 cStr    : string;
begin
 with (Sender as TDBGrid).Canvas do begin
   {Table1Notes is the TMemoField}
   xBlob := TBlobStream.Create( TBlobField( xTable.FieldByName(cField)),
bmRead );
   FillChar( cChars, SizeOf( cChars ), #0 );   {terminate the null string}
   xBlob.Read( cChars, 500 );    {read chars from memo into blobStream}
   xBlob.Free;
   cStr := StrPas( cChars );
   while Pos( #13, cStr ) > 0 do              {remove carriage returns and}
     cStr[ Pos( #13, cStr )] := ' ';          {line feeds}
   While Pos( #10, cStr ) > 0 do
     cStr[ Pos( #10, cStr )] := ' ';
   FillRect( Rect );                          {clear the cell}
   TextOut( Rect.Left + 3, Rect.Top + 2, cStr ){fill cell with memo data}
 end;
end; {DrawMemoCell }

Hope it will work for you.
Marcio Ehrlich