BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Help with AfterScroll Event for Tadoquery

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (ADO)
View previous topic :: View next topic  
Author Message
chris
Guest





PostPosted: Tue Aug 09, 2005 1:42 am    Post subject: Help with AfterScroll Event for Tadoquery Reply with quote




Hi Guys, I do not understand how to write a code for
afterscroll event.
Here is my problem : I run query, display values in the grid,
then once I user hit on single record I want to show an image
on the form ( MS Sql has one field declared as blob)
I was able to do this by using drop components from Delphi ( ver 7). But when I try to do everything myself I am not able to see the image. Here is my code, any help but we great:

procedure TfrmImageViewer.btnRunQueryClick(Sender: TObject);
var
sSql : String;
begin
sSql := 'select * from ' + sViewName + ' where stationId = ' +
'''' + edtStationName.text + '''';
with oAdoquery do
begin
Close;
SQL.Clear;
SQL.Add(sSql);
Open;
ExecSQL
end;
with oDataSource do
begin
DataSet := oAdoquery;
end;
//+++++++++++
DBGrid1.DataSource := oDataSource;
//How to INVOKE AfterScroll Event
//oAdoquery.AfterScroll(dataSet: TDataSet0);
end;

procedure TfrmImageViewer.oAdoqueryAfterScroll(DataSet: TDATASet);
var
P : TADOBlobStream;
jpegpic : TJPEGImage;
oBitmap: TBitmap;
blImage : TBlobField;

begin
jpegpic := TJPEGImage.Create;
oBitmap := TBitmap.create;
//IS THIS STATEMENT CORRECT********************************
//image blob field in the database
blImage.Assign(oDataSource.DataSet.FieldByName('image'));

p := TADOBlobStream.Create(blImage,bmRead);
If p.Size <> 0 Then
begin
jpegpic.LoadFromStream(p);
oBitmap.Width := trunc(jpegpic.Width * 0.5);
oBitmap.Height := TRUNC(jpegpic.Height * 0.5);
oBitmap.PixelFormat := pf24bit;
oBitmap.Canvas.StretchDraw(oBitmap.Canvas.ClipRect,jpegpic);
Image1.Picture.Graphic := oBitmap;

end;

end;
Back to top
chris
Guest





PostPosted: Tue Aug 09, 2005 12:14 pm    Post subject: Re: Help with AfterScroll Event for Tadoquery Reply with quote




Brian Bushay TeamB <BBushay (AT) Nmpls (DOT) com> wrote:
Quote:

Hi Guys, I do not understand how to write a code for
afterscroll event.
Here is my problem : I run query, display values in the grid,
then once I user hit on single record I want to show an image
on the form ( MS Sql has one field declared as blob)
I was able to do this by using drop components from Delphi ( ver 7). But when I try to do everything myself I am not able to see the image. Here is my code, any help but we great:
I don't have time to test your code but I will give you code I have tested

procedure TForm1.Table1AfterScroll(DataSet: TDataSet);
var
MS: TMemoryStream;
J1: TJPEGImage;
begin
J1 := TJPEGImage.Create;
MS := TMemoryStream.Create;
try
TBlobField(DataSet.Fieldbyname('myBlob')).SaveToStream(MS);
MS.Seek(0,soFromBeginning);
with J1 do begin
PixelFormat := jf24Bit;
Scale := jsFullSize;
Grayscale := False;
Performance := jpBestQuality;
ProgressiveDisplay := True;
ProgressiveEncoding := True;
LoadFromStream(MS);
end;
if MS.Size >0 then
Image1.Picture.Assign(J1)
else
Image1.Picture.Assign(nil);

finally
J1.Free;
MS.Free;
end;
end;

--
Brian Bushay (TeamB)
[email]Bbushay (AT) NMPLS (DOT) com[/email]

Thanks Brian,
very much appreciated.
Chris



Back to top
chris
Guest





PostPosted: Tue Aug 09, 2005 1:27 pm    Post subject: Re: Help with AfterScroll Event for Tadoquery Reply with quote




Brian Bushay TeamB <BBushay (AT) Nmpls (DOT) com> wrote:
Quote:

Hi Guys, I do not understand how to write a code for
afterscroll event.
Here is my problem : I run query, display values in the grid,
then once I user hit on single record I want to show an image
on the form ( MS Sql has one field declared as blob)
I was able to do this by using drop components from Delphi ( ver 7). But when I try to do everything myself I am not able to see the image. Here is my code, any help but we great:
I don't have time to test your code but I will give you code I have tested

procedure TForm1.Table1AfterScroll(DataSet: TDataSet);
var
MS: TMemoryStream;
J1: TJPEGImage;
begin
J1 := TJPEGImage.Create;
MS := TMemoryStream.Create;
try
TBlobField(DataSet.Fieldbyname('myBlob')).SaveToStream(MS);
MS.Seek(0,soFromBeginning);
with J1 do begin
PixelFormat := jf24Bit;
Scale := jsFullSize;
Grayscale := False;
Performance := jpBestQuality;
ProgressiveDisplay := True;
ProgressiveEncoding := True;
LoadFromStream(MS);
end;
if MS.Size >0 then
Image1.Picture.Assign(J1)
else
Image1.Picture.Assign(nil);

finally
J1.Free;
MS.Free;
end;
end;

--
Brian Bushay (TeamB)
[email]Bbushay (AT) NMPLS (DOT) com[/email]


Brian,
I have just tested a code in my application, and it worked like charm.
I am really greatful for your help.
Best,
Chris


Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (ADO) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.