Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > DB-Aware

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 06-23-2002, 06:05 AM
murphys murphys is offline
Senior Member
 
Join Date: Aug 2001
Posts: 2,948
Default 2 questions about DBGrid

1) if the same DBGrid, is used for 2 different queries
is there a way to automatically change the titles according to the query, or must i do it each time i open the other query? (the titles are not exactly as the "select" part of the query)

2) i use access MDB file, and one of the fields is Memo.
how can i show its data (even part of it) inside a DBGrid?

10x
Amos
Reply With Quote
  #2  
Old 06-23-2002, 05:26 PM
HTML HTML is offline
Senior Member
 
Join Date: Jan 2001
Posts: 2,977
Default RE: 2 questions about DBGrid

Hello, :-)

Answer to question #2.

{Courtesy of Brian Bushay(TeamB) }

Below is an example showing the use of a TBlobStream object in an OnDrawDataCell
event procedure to display the first 50 characters of a memo field in a TDBGrid.

procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
Field: TField; State: TGridDrawState);
var
Buf: array [0..51] of Char;
BS: TBlobStream;
S: String;
begin
{Check to see if currently-drawn field is a memo field}
if Field is TMemoField then begin
{Create the TBlobStream object}
BS := TBlobStream.Create(TMemoField(Field), bmRead);
try
{Fill buffer with nulls}
FillChar(Buf, 51, #0);
{Read 50 characters from memo field into buffer}
BS.Read(Buf, 50);
{Copy from null-terminated buffer to Pascal String}
S := StrPas(Buf);
{Cosmetic: show that data is continued}
S := S + '...';
{Put a null character in place of any carriage-returns}
while (Pos(#13, Buf) > 0) do
S[Pos(#13, Buf)] := #0;
{Draw String to grid's Canvas within cell's boundaries}
with TDBGrid(Sender).Canvas do begin
{Clear current cell}
FillRect(Rect);
{Draw String text}
TextOut(Rect.Left, Rect.Top, S);
end;
finally
{Destroy TBlobStream object connected to current record}
BS.Free;
end;
end;
end;
Reply With Quote
  #3  
Old 06-23-2002, 10:55 PM
murphys murphys is offline
Senior Member
 
Join Date: Aug 2001
Posts: 2,948
Default RE: 2 questions about DBGrid

BS := TBlobStream.Create(TMemoField(Field), bmRead);

on the above line on runtime it gives me this error:
invalid class typecast

10x
Amos
Reply With Quote
  #4  
Old 06-24-2002, 09:10 AM
HTML HTML is offline
Senior Member
 
Join Date: Jan 2001
Posts: 2,977
Default RE: 2 questions about DBGrid

Hello, :-)

I see you got it fixed already :-) . The code I posted should have worked, I got it from Borland's help site. Are you using a TTable? or a descendant?

But just in case try this line

BlobStream1:=Table1.CreateBlobStream(FieldByName(M emoFieldName),bmWrite );
Reply With Quote
  #5  
Old 06-24-2002, 10:50 PM
murphys murphys is offline
Senior Member
 
Join Date: Aug 2001
Posts: 2,948
Default RE: 2 questions about DBGrid

HI

im using ADO, and yes i got it worked eventually :")

10x
Amos
Reply With Quote
  #6  
Old 07-09-2002, 06:29 AM
jzeitts jzeitts is offline
Junior Member
 
Join Date: Apr 2001
Posts: 3
Default RE: 2 questions about DBGrid

Thank you. Most of this worked perfectly for me. The one problem I am still having is with the code to remove carriage-returns (which I do need to do). The code you gave was 'while (Pos(#13,Buf)>0) do
S[Pos{#13,Buf)] := #0;'

This puts me into a loop and crashes the app. If I comment out those two lines of code, it works fine but leaves the carriage returns in.

Would appreciate any further help you can offer.

Thanks


JZeitts
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:18 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.