DB Grid Question...

I'm using a DB Grid to display the contents of a database. The Memo field though doesn't show up, it just says: (MEMO).  How can I have it display the contents of the Memo field when the box is double-clicked?
Who is Participating?
Phoenix_sConnect With a Mentor Commented:
My answer.... ;)

try this DrawMemoCell proc  adapted straight from Borlands Delphi FAQ :
procedure TResultsForm.DBGrid1DrawDataCell(Sender: TObject;
  const Rect: TRect; Field: TField; State: TGridDrawState);
  if Field is TMemoField then
    DrawMemoCell( Sender, Rect, ResultsTable, 'TITLE');
procedure DrawMemoCell( Sender: TObject; const Rect: TRect;
                        xTable: TTable; cField: string );
  cChars  : array [0..501] of char;  {array size is number of characters needed}
  xBlob  : TBlobStream;              {from the memo field}
  cStr    : string;
  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; {DrawMemoCell}

Regards Barry
you could put up a memo component under the grid which'd show the memo data as the records scrolled by on the grid, or if you even want to have a small modal window show up by clicking on the field in the grid

all's you'd have to do for the latter is stick a click event on the grid which'd open the memo display dialog

ex.  make a small form, stick a dbmemo on it.

in the gridclick event... create the form, set the datasource property of the memo control to the calling form's datasource, show it modally, then dispose of it when you're done

hope this helps... ;)
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

dokkenAuthor Commented:

I'm using that DBISAM database component and the TTable turned out to not be compatible with it.


Your method works great. Post something as an answer so I can give you the points.

U can place a DB MEMO in the form .
Set it's  datafield and datasource.
On the Gird's MouseClick get the coordinates of the memo cell using function CellRect.
Set the DBMEMO's coordinates to the grids cells  using function Setbounds .

dokkenAuthor Commented:

Thanks again for the answer.
All Courses

From novice to tech pro — start learning today.