Thanks for the code - a little tweeking of my code while using your
code made it work just as i wanted.
thanks a bunch
Tony
--- In [email protected], Theodoros Bebekis <[EMAIL PROTECTED]>
wrote:
>
> O/H tony_bat Ýãñáøå:
> >
> >
> > using D7 professional, firebird 2.0.3, firebird odbc 2.0
> > I have google until tired.
> > tried tmemorystream, tstream, tblobstream,
> > created tblobfield tried assigning the value. I admit i do not
know
> > what to try next but i have not given up.
> > all the examples I have seen on web don't work for me.
> > I read something about tAdoblobstream but get error each time I
try to
> > create object: delphi does not recognize tadoblobstream.
> >
> > I am able to store jpg to database now I can not get it back. I
know I
> > stored it because I used a third party tool and I see the stored
> > picture.
> > I am using ado components.
> >
> > question 1. how do i get to use tadoblobstream.
> > question 2. will anyone share a tid bit of code to do this.
> >
> > Thanks
> > In advance
> > Tony
>
>
> Tony
>
> 1. You don't have to. Every TDataset descendant provides
> its own version of a TXXXBlobStream. The TBlobField calls
> a virtual method of the TDataset to load the blob data and
> that call ends up creating the right TXXXBlobStream.
> If you know your field is not null then you just
> MyBlobField.SaveToStream(MyMemoryStream);
> That call will actually initiate the call sequence
> I just described.
>
>
> 2. Yes.
>
>
> I'm not sure but I think I remember Delphi's 7 TDBImage
> has some troubles with image types other than bitmaps.
> Please, correct me if I'm wrong here. Not sure at all.
>
>
> Anyway, try the following functions and let me know.
> Using them you should be able to load the image
> into a TImage control.
>
> type
> TGraphicType = ( gtNone
> ,gtICO
> ,gtBMP
> ,gtWMF
> ,gtJPG
> );
>
>
> (*------------------------------------------------------------------
----------
> Returns the type of graphic the stream may contains
> ------------------------------------------------------------------
----------*)
> function TAppUtls.GetGraphicType(Stream: TStream): TGraphicType;
> var
> Buf : Word;
> begin
> Result := gtNone;
> if Assigned(Stream) and (Stream.Size > SizeOf(Buf)) then
> begin
> Stream.Position := 0;
> Stream.Read(Buf, SizeOf(Buf));
> case Buf of
> $0000 : Result := gtICO;
> $0001 : Result := gtBMP;
> $4D42 : Result := gtBMP;
> $CDD7 : Result := gtWMF;
> $D8FF : Result := gtJPG;
> end;
> end;
> end;
> (*------------------------------------------------------------------
----------
> Tries to recognize the image format, the Stream data contains.
> Loads Stream contents into Graphic by creating the appropriate
Graphic object.
> ------------------------------------------------------------------
----------*)
> function TAppUtls.LoadGraphicFromStream(Stream: TStream; var
Graphic: TGraphic): TGraphicType;
> var
> GraphicType: TGraphicType;
> begin
> Result := gtNone;
>
> GraphicType := GetGraphicType(Stream);
>
> case GraphicType of
> gtICO : Graphic := TIcon.Create;
> gtBMP : Graphic := TBitmap.Create;
> gtWMF : Graphic := TMetafile.Create;
> gtJPG : Graphic := TJPEGImage.Create;
> else Graphic := nil;
> end;
>
> if Assigned(Graphic) then
> try
> Stream.Position := 0;
> Graphic.LoadFromStream(Stream);
> Result := GraphicType;
> except
> Graphic.Free;
> Graphic := nil;
> end;
>
> end;
> (*------------------------------------------------------------------
----------*)
> function TAppUtls.LoadPictureFromStream(Stream: TStream; Picture:
TPicture): TGraphicType;
> var
> Graphic : TGraphic;
> begin
> Result := gtNone;
> Graphic := nil;
>
> if Assigned(Stream) and Assigned(Picture) then
> begin
> Result := LoadGraphicFromStream(Stream, Graphic);
> Picture.Assign(Graphic); // Graphic can be NIL, no problem
with that
> FreeAndNil(Graphic);
> end;
>
> end;
> (*------------------------------------------------------------------
----------*)
> function TAppUtls.LoadPictureFromField(Field: TBlobField; Picture:
TPicture): TGraphicType;
> var
> MS : TMemoryStream;
> begin
> Result := gtNone;
>
> if Assigned(Field) and (not Field.IsNull) then
> begin
> MS := TMemoryStream.Create;
> try
> Field.SaveToStream(MS);
> MS.Position := 0;
> Result := LoadPictureFromStream(MS, Picture);
> finally
> MS.Free;
> end;
> end;
> end;
>
> --
> Regards
> Theo
>
> ------------------------
> Theo Bebekis
> Thessaloniki, Greece
> ------------------------
> Greek_Delphi_Prog : a Delphi Programming mailing list in Greek at
> http://groups.yahoo.com/group/Greek_Delphi_Prog
>
> CSharpDotNetGreek : A C# and .Net mailing list in Greek language at
> http://groups.yahoo.com/group/CSharpDotNetGreek
>
> atla_custom : a Unisoft Atlantis Customization mailing list at
> http://groups.yahoo.com/group/atla_custom
> ------------------------
>