?
Solved

DBGrid/TField and memofields

Posted on 1997-08-14
4
Medium Priority
?
323 Views
Last Modified: 2010-04-06
Hi

I'm trying to print/display memofields from a DBGrid, but I just seem to get stuck whatever I do to read the memofield.

I the DBGrid (wwDBGrid) to display columns from SQL-statements (which the
end-user defines) and would then like to print the grid. I've only got a
problem with the memofields-columns (which displays just displays "(Memo)").

Is this the correct way to do it? And what do I need to display/print the memofield?

   if Fields[FieldNo].DataType = ftMemo then
   begin
     with Fields[FieldNo] do
     begin
       GetMem(TheField, Datasize);   { Allocate space }
       if GetData(TheField) then
       begin

          how do I use the "TheField"?
          how can I extract the data?


       end;
       FreeMem(TheField,DataSize);
     end;
   end;

I just think I have tried every possible way to extract the data from
"TheField", but I still haven't got the hang of it.

Can you please help me?

Jakob Hoffmann

0
Comment
Question by:alijakob
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 

Expert Comment

by:hkelmer
ID: 1341426
why don´t you use InfoPower or DBpower or any other vcl that
has this special dbgrid with memos?
just check their demo´s

0
 
LVL 1

Expert Comment

by:Zonnald
ID: 1341427
alijakob,

I have a better ***Free*** solution but really could use the points - depending on the size of the MEMO field's data.

Please assess hkelmer's answer if you will.

Zonnald
0
 

Author Comment

by:alijakob
ID: 1341428
Hello

I have checked the InfoPower demos - there's no information about processing the contents of memofields.

My application is based on the InfoPower wwDBGrids where I do use the facility to display memofields. Using the wwDBGrids, it's not possible to print/use the contents of the memofields directly.

I have however, found a solution to my problems which seems to work - it'll only show the first 255 characters of the memofield (but the whole string is there!):

FieldSize   : LongInt;      { Will hold the fieldsize }
bstTheField : TBlobStream;  { The connection between us and the memofield }
TheField    : PChar;        { Will hold the contents read from the memofield }

bstTheField := TBlobStream.Create((Fields[FieldNo] as TMemoField),bmRead);
FieldSize   := bstTheField.Seek(0,2);  { Go to end of memofield to find size }
GetMem(TheField,FieldSize + 1);  { Allocate memory for contents }
if (TheField = nil) then raise Exception.Create('Not enough memory');
bstTheField.Seek(0,0);  { Go to start of field before reading contents }
FillChar(TheField^,FieldSize + 1,#0);  { Initialize the string }
bstTheField.Read(TheField^,FieldSize);  { Read contents of field }
showmessage('memo='+strpas(TheField)); {only shows the first 255 characters}

Jakob
0
 
LVL 2

Accepted Solution

by:
icampbe1 earned 50 total points
ID: 1341429
I'm gonna step out on a limb here and hope that this is a sensible answer.  I am using a DBCntrlGrid very successfully for this purpose.  It is a very good solution.

The DBCtrlGrid lets to put compnents of your own choice on every 'record' of the dataset.  This includes a DBMemo component.  It kind of like designing your own little form for each record.  It is very slick and I find the result look better than a plain DBGrid.

Hope this is acceptable,

Ian C.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question