Board index » delphi » To those TStream gurus out there

To those TStream gurus out there

 This should be easy...

I'm trying to instantiate a TBLOBStream object using the following code:

var
  ImgStream: TBLOBStream;
begin
  tksimages.Open;
  tksimages.Insert;
  ImgStream.Create( tksimagesIMAGE, bmReadWrite );
end;

tksimagesIMAGE is defined as TBlobField (I also tried TGraphicField)
elsewhere
tksimages is an OracleDataSet

I'm getting an "Access Violation at..." message when I run this code.  I
tried using bmRead and bmWrite as the mode for opening the stream, with
similar results (Access Violation at different addresses).

Is there something basic I'm missing?

I'm using Delphi 3.02, and the ultimate goal of this code is to take an
image in a TJPEGImage object and save it to an Oracle database.  If
anyone has any ideas on other ways to do this , that would be greatly
appreciated as well.  Thanks,

Kaushal Sheth
ksh...@iname.com

 

Re:To those TStream gurus out there


In article <34CF8058.27178...@boi48.boi.hp.com>, Kaushal Sheth

Quote
<jts...@boi48.boi.hp.com> writes:
>  ImgStream.Create( tksimagesIMAGE, bmReadWrite );
>end;

>tksimagesIMAGE is defined as TBlobField (I also tried TGraphicField)
>elsewhere
>tksimages is an OracleDataSet

>I'm getting an "Access Violation at..." message when I run this code.

I'm not surprised - ALL objects you create have syntax of the form :-

ObJect_Name := TObject_Type.Create(Params_Needed_To_Create);

(Params_Needed_To_Create) may of course be empty for some objects.

Try using . . .

ImgStream :=  TBLOBStream.Create( tksimagesIMAGE, bmReadWrite );

All you had was a pointer address to hold the address of an object, you had no
rights to access the memory at whatever garbage was in that address - hence the
GPF.

An easy and common mistake <g>

Alan Lloyd
alangll...@aol.com

Re:To those TStream gurus out there


it should be

ImgStream := TBlobStream.create(( tksimagesIMAGE, bmReadWrite );

Rick Peterson

Quote
Kaushal Sheth wrote in message <34CF8058.27178...@boi48.boi.hp.com>...
> This should be easy...

>I'm trying to instantiate a TBLOBStream object using the following code:

>var
>  ImgStream: TBLOBStream;
>begin
>  tksimages.Open;
>  tksimages.Insert;
>  ImgStream.Create( tksimagesIMAGE, bmReadWrite );
>end;

>tksimagesIMAGE is defined as TBlobField (I also tried TGraphicField)
>elsewhere
>tksimages is an OracleDataSet

>I'm getting an "Access Violation at..." message when I run this code.  I
>tried using bmRead and bmWrite as the mode for opening the stream, with
>similar results (Access Violation at different addresses).

>Is there something basic I'm missing?

>I'm using Delphi 3.02, and the ultimate goal of this code is to take an
>image in a TJPEGImage object and save it to an Oracle database.  If
>anyone has any ideas on other ways to do this , that would be greatly
>appreciated as well.  Thanks,

>Kaushal Sheth
>ksh...@iname.com

Re:To those TStream gurus out there


In article <34CF8058.27178...@boi48.boi.hp.com>,
jts...@boi48.boi.hp.com says...

Quote

<snip>
>   ImgStream.Create( tksimagesIMAGE, bmReadWrite );

This is not the correct way to create objects. The object you're
referring to (ImgStream) does not exist (it's a pointer to
anywhere, or nowhere depending on your point of view). The
correct syntax is:

ImgStream := TBLOBStream.Create( tksimagesIMAGE, bmReadWrite );

This will instantiate an object of class TBLOBStream, and assign
a pointer to that object to the ImgStream pointer.

<snip>

M.

--
Author of several unknown utilities for DOS and Windows.
http://www.delfidata.no/users/~martin
mailto:martin.lars...@delfidata.no

Re:To those TStream gurus out there


Thanks,  I'll try it out tonight.  As you can tell, I'm a Delphi newbie
:)

Kaushal Sheth

Quote
Martin Larsson wrote:
> In article <34CF8058.27178...@boi48.boi.hp.com>,
> jts...@boi48.boi.hp.com says...

> <snip>
> >   ImgStream.Create( tksimagesIMAGE, bmReadWrite );

> This is not the correct way to create objects. The object you're
> referring to (ImgStream) does not exist (it's a pointer to
> anywhere, or nowhere depending on your point of view). The
> correct syntax is:

> ImgStream := TBLOBStream.Create( tksimagesIMAGE, bmReadWrite );

> This will instantiate an object of class TBLOBStream, and assign
> a pointer to that object to the ImgStream pointer.

> <snip>

> M.

> --
> Author of several unknown utilities for DOS and Windows.
> http://www.delfidata.no/users/~martin
> mailto:martin.lars...@delfidata.no

Re:To those TStream gurus out there


In article <34CF95C0.C10B...@boi48.boi.hp.com>,
jts...@boi48.boi.hp.com says...

Quote
> Thanks,  I'll try it out tonight.  As you can tell, I'm a Delphi newbie
> :)

Well, we've all been there!

M.

--
Author of several unknown utilities for DOS and Windows.
http://www.delfidata.no/users/~martin
mailto:martin.lars...@delfidata.no

Re:To those TStream gurus out there


I tried to instantiate the TBlobStream object using the following code:

var
  KSImgStream: TBlobStream;
  tksimagesIMAGE: TBlobField; // a field in my tksimages data set
begin
  KSImgStream := TBlobStream.Create(tksimagesIMAGE, bmReadWrite);
end;

However, when I run this code, I get the message:
Project Imgtest.exe raised exception class EInvalidCast with message
'Invalid class typecast'

When I tried the same code on another machine, I got a compile-time error
saying something like "undeclared identifier bmReadWrite".  I included the
dbtables unit, is there another unit I also need to include?

What am I doing wrong here?  It seems to me like a bug in Delphi.
Someone help me please.

Kaushal Sheth
ksh...@global.california.com

Quote
Martin Larsson wrote:
> In article <34CF95C0.C10B...@boi48.boi.hp.com>,
> jts...@boi48.boi.hp.com says...
> > Thanks,  I'll try it out tonight.  As you can tell, I'm a Delphi newbie
> > :)

> Well, we've all been there!

> M.

> --
> Author of several unknown utilities for DOS and Windows.
> http://www.delfidata.no/users/~martin
> mailto:martin.lars...@delfidata.no

Re:To those TStream gurus out there


In article <34D0B9AD.52FEF...@boi48.boi.hp.com>,
jts...@boi48.boi.hp.com says...

Quote
> I tried to instantiate the TBlobStream object using the following code:

> var
>   KSImgStream: TBlobStream;
>   tksimagesIMAGE: TBlobField; // a field in my tksimages data set
> begin
>   KSImgStream := TBlobStream.Create(tksimagesIMAGE, bmReadWrite);
> end;

The same applies to TBlobField as to the stream. What you're
doing in the var section is to declare a pointer to an object.
The object does not exist. So you need to create it. Usually, you
create objects by calling the constructor on the wanted objects
class. The return value is a new (initialized) object. If the
creation fails for any reason, an exception is thrown (unless you
turn that feature off).
So, you need:
  tksimagesImage := TBlobField.Create(Application // or nil);

M.

--
Author of several unknown utilities for DOS and Windows.
http://www.delfidata.no/users/~martin
mailto:martin.lars...@delfidata.no

Re:To those TStream gurus out there


Ok,  the sample code I submitted earlier isn't exactly how I'm using the
TBlobField.  It is actually a field in my dataset (tksimages).  What I do is:

tksimages.Open;
tksimages.Insert;
KSImgStream := TBlobStream.Create(tksimagesIMAGE, bmReadWrite);

When I open the dataset, doesn't it automatically create the underlying
fields in the dataset?  Or does it do that only if I have a data-aware
control linked to that field?  I guess that's my problem.  I should manually
create the field before using it.

Then my question is, why does it not give a GPF (invalid address) like it
does for KSImgStream?  Oh well, I guess I'll try it out and see if it works.

Thanks,
Kaushal Sheth

Quote
Martin Larsson wrote:
> In article <34D0B9AD.52FEF...@boi48.boi.hp.com>,
> jts...@boi48.boi.hp.com says...
> > I tried to instantiate the TBlobStream object using the following code:

> > var
> >   KSImgStream: TBlobStream;
> >   tksimagesIMAGE: TBlobField; // a field in my tksimages data set
> > begin
> >   KSImgStream := TBlobStream.Create(tksimagesIMAGE, bmReadWrite);
> > end;

> The same applies to TBlobField as to the stream. What you're
> doing in the var section is to declare a pointer to an object.
> The object does not exist. So you need to create it. Usually, you
> create objects by calling the constructor on the wanted objects
> class. The return value is a new (initialized) object. If the
> creation fails for any reason, an exception is thrown (unless you
> turn that feature off).
> So, you need:
>   tksimagesImage := TBlobField.Create(Application // or nil);

> M.

> --
> Author of several unknown utilities for DOS and Windows.
> http://www.delfidata.no/users/~martin
> mailto:martin.lars...@delfidata.no

Re:To those TStream gurus out there


Quote

>Well, do you know why the TDBImage in Delphi 3.0 doesn't work with JPEG
>images?  I don't understand why it wouldn't (if the normal TImage does).

>You could try getting the TJPEGImage component from The Delphi Super
>Page. If you were using this, I could tell you exactly what to do.

>Daniel.
>zzden...@fow.uq.net.au

Actually, TImage does not work with JPEG images either.  It only supports Bitmap
and DIB(?).  TJPEGImage is included with Delphi 3.0, and I'm using it to convert
the image I acquire to a JPEG.  The problem I'm having is getting this compressed
image into the database.

I'm now trying to use streams to save the image to the database as follows.  I
have a  dataset named timages (Oracle DataSet).  This dataset has a field named
timagesIMAGE (of type TBlobField).  When I open the form, I open the dataset
using:

timages.Open;
timages.Insert;

After my image has been acquired (to the clipboard), I do the following:

var
  JPG: TJPEGImage;
  ImgStream: TBlobStream;
begin
  JPG.Create;
  JPG.LoadFromClipboard; // I'm don't remember the exact syntax right now.  The
idea is to load the image into the JPG
// The code upto here works fine

// I start getting problems with the following code
  ImgStream := TBlobStream.Create(timagesIMAGE, bmReadWrite);

The above line results in an error stating "Project Imgtest.exe raised exception
class EInvalidCast with message 'Invalid class typecast'"

Someone pointed out that I need to create the field before using it (I thought
the field would get created automatically when I open the dataset -- that's what
the documentation seems to say.  Regardless, I added the following code:

  timagesIMAGE := TBlobField.Create(Application); // I also tried using nil as
the parent
  ImgStream := TBlobStream.Create(timagesIMAGE, bmReadWrite);

Now it results in a GPF (read of address FFFFFFFF)

I even tried declaring a new variable:
var
  ImgField: TBlobField;
...
begin
  ImgField := TBlobField.Create(Application); // I also tried using nil as the
parent
  ImgStream := TBlobStream.Create(ImgField, bmReadWrite);

but this also results in the same error.

I can't for the life of me figure out what the problem could be.  I've certainly
learned a lot in the past few days trying ot get this code to work, but I just
wish the code would work at this point.

Thanks to everyone who responded, and if you can think of anything else that
might work, that would be great.

Also, does anyone know of any components I could buy that would let me do what
I'm trying?  It's really very simple (I thought) -- acquire an image from a
digital camera, compress it (in JPG format), and store the image in an Oracle
database.  Of course, I need to be able to read the image from the database,
uncompress it and display it as well.

For the acquisition piece, I'm using Olympus TwainWizard (I also tried
EnhancedTwain, iTwain, and a bunch of other ones).  For accessing Oracle, I'm
using DOA shareware component, which gives you Oracle DataSet component, which is
similar to Delphi's TTable.  I'm open to use anything to store (and retrieve) the
compressed image to the database.  BTW, I'm using Delphi 3.02

Kaushal Sheth
ksh...@global.california.com

Re:To those TStream gurus out there


[snip]

Quote

> // I start getting problems with the following code
>   ImgStream := TBlobStream.Create(timagesIMAGE, bmReadWrite);

> The above line results in an error stating "Project Imgtest.exe raised exception
> class EInvalidCast with message 'Invalid class typecast'"

 You are limited to what can be cast to TBlobStream. Try this and see if
it
corrects the problem .

 var
   ImgStream: TBlobStream;
 begin
   ImgStream := TBlobStream.Create(timagesIMAGE as TBlobField,
bmReadWrite);

Robin

Other Threads