alijakob
asked on
DBGrid/TField and memofields
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
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
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
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
ASKER
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^,FieldSi ze + 1,#0); { Initialize the string }
bstTheField.Read(TheField^ ,FieldSize ); { Read contents of field }
showmessage('memo='+strpas (TheField) ); {only shows the first 255 characters}
Jakob
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
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^,FieldSi
bstTheField.Read(TheField^
showmessage('memo='+strpas
Jakob
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
has this special dbgrid with memos?
just check their demo´s