Board index » delphi » Invalid class typecast

Invalid class typecast

Hi all!!!

When I try to load or save a binary data to blob field, I get this error:
---------------------------
De{*word*81} Exception Notification
---------------------------
Project Project1.exe raised exception class EInvalidCast with message
'Invalid class typecast'. Process stopped. Use Step or Run to continue.
---------------------------
OK   Help
---------------------------

I'm using D7, FireBird 1.04, the blob's field type is 0 and I have a lot of
binary data on this DB like MP3, GIF, BMP, JPG, AVI, etc. When I use
IBExpress, everything works fine.

Thanks,

Rodrigo.

 

Re:Invalid class typecast


I am successfully working blobs with dbExpress/Firebird.
my blob is currently defined as BLOB SUB_TYPE BLR SEGMENT SIZE 1, but I
do not know if that is best.
Quote
Rodrigo C Souza wrote:
> Hi all!!!

> When I try to load or save a binary data to blob field, I get this error:
> ---------------------------
> De{*word*81} Exception Notification
> ---------------------------
> Project Project1.exe raised exception class EInvalidCast with message
> 'Invalid class typecast'. Process stopped. Use Step or Run to continue.
> ---------------------------
> OK   Help
> ---------------------------

> I'm using D7, FireBird 1.04, the blob's field type is 0 and I have a lot of
> binary data on this DB like MP3, GIF, BMP, JPG, AVI, etc. When I use
> IBExpress, everything works fine.

> Thanks,

> Rodrigo.

Re:Invalid class typecast


Quote
> I am successfully working blobs with dbExpress/Firebird.
> my blob is currently defined as BLOB SUB_TYPE BLR SEGMENT SIZE 1, but I
> do not know if that is best.

The error he is getting is a Delphi error. Can you show a piece
of code?

--

With regards,

Martijn Tonies
Database Workbench - the developer tool for InterBase & Firebird
Upscene Productions
http://www.upscene.com

See you at the First European Firebird Conference in May in Fulda, Germany
http://www.firebird-conference.com

Quote

> Rodrigo C Souza wrote:
> > Hi all!!!

> > When I try to load or save a binary data to blob field, I get this error:
> > ---------------------------
> > De{*word*81} Exception Notification
> > ---------------------------
> > Project Project1.exe raised exception class EInvalidCast with message
> > 'Invalid class typecast'. Process stopped. Use Step or Run to continue.
> > ---------------------------
> > OK   Help
> > ---------------------------

> > I'm using D7, FireBird 1.04, the blob's field type is 0 and I have a lot of
> > binary data on this DB like MP3, GIF, BMP, JPG, AVI, etc. When I use
> > IBExpress, everything works fine.

> > Thanks,

> > Rodrigo.

Re:Invalid class typecast


Of Course, here it goes:

procedure TForm1.Button1Click(Sender: TObject);
var
   MyBlobStream : TBlobStream;
   MyFileStream : TFileStream;
begin
  try
    SQLQuery1.Active:=true;

Error here>>>>    MyBlobStream :=
TBlobStream.Create(SQLQuery1.Fieldbyname('MyFileOnDataBase') as TBlobField,
bmRead);

    MyFileStream := TFileStream.Create('C:\temp_file.mp3', fmCreate or
fmOpenWrite);
    MyFileStream.CopyFrom(MyBlobStream, 0);
  finally
    MyFileStream.Free;
    MyBlobStream.Free;
end;
end;

On this table I'm saving some MP3 files. When I try to save the file using
dbexpress (SQLQuery) I get the same error.
I think that I'm using the wrong class, Am I?

And I would like to complete my question asking to Richard Gilbert what kind
of BLOB type is this BLR? I never saw this type of BLOB.

Thanks for help,

Rodrigo C. Souza

Quote
"Martijn Tonies" <m.tonies@upscene!nospam!.com> wrote in message

news:3e8c8c52@newsgroups.borland.com...
Quote
> > I am successfully working blobs with dbExpress/Firebird.
> > my blob is currently defined as BLOB SUB_TYPE BLR SEGMENT SIZE 1, but I
> > do not know if that is best.

> The error he is getting is a Delphi error. Can you show a piece
> of code?

> --

> With regards,

> Martijn Tonies
> Database Workbench - the developer tool for InterBase & Firebird
> Upscene Productions
> http://www.upscene.com

> See you at the First European Firebird Conference in May in Fulda, Germany
> http://www.firebird-conference.com

> > Rodrigo C Souza wrote:
> > > Hi all!!!

> > > When I try to load or save a binary data to blob field, I get this
error:
> > > ---------------------------
> > > De{*word*81} Exception Notification
> > > ---------------------------
> > > Project Project1.exe raised exception class EInvalidCast with message
> > > 'Invalid class typecast'. Process stopped. Use Step or Run to
continue.
> > > ---------------------------
> > > OK   Help
> > > ---------------------------

> > > I'm using D7, FireBird 1.04, the blob's field type is 0 and I have a
lot of
> > > binary data on this DB like MP3, GIF, BMP, JPG, AVI, etc. When I use
> > > IBExpress, everything works fine.

> > > Thanks,

> > > Rodrigo.

Re:Invalid class typecast


Hi,

Quote
> procedure TForm1.Button1Click(Sender: TObject);
> var
>    MyBlobStream : TBlobStream;
>    MyFileStream : TFileStream;
> begin
>   try
>     SQLQuery1.Active:=true;

> Error here>>>>    MyBlobStream :=
> TBlobStream.Create(SQLQuery1.Fieldbyname('MyFileOnDataBase') as TBlobField,
> bmRead);

Did you check the classtype of the field that comes back with FieldByName?
(You can, amongst other ways, simply do this by:
ShowMessage(SQLQuery1.FieldByName('MyFileOnDataBase').ClassName); )

Quote
>     MyFileStream := TFileStream.Create('C:\temp_file.mp3', fmCreate or
> fmOpenWrite);
>     MyFileStream.CopyFrom(MyBlobStream, 0);
>   finally
>     MyFileStream.Free;
>     MyBlobStream.Free;
> end;
> end;

> On this table I'm saving some MP3 files. When I try to save the file using
> dbexpress (SQLQuery) I get the same error.
> I think that I'm using the wrong class, Am I?

> And I would like to complete my question asking to Richard Gilbert what kind
> of BLOB type is this BLR? I never saw this type of BLOB.

BLR? How did you create this blob column? The pre-defined types are
TEXT (1) and BINARY (0). In subtype 0 you can put anything you like
(in 1 also, but hey - it's the standard). If you're using BLR, better not.

--

With regards,

Martijn Tonies
Database Workbench - the developer tool for InterBase & Firebird
Upscene Productions
http://www.upscene.com

See you at the First European Firebird Conference in May in Fulda, Germany
http://www.firebird-conference.com

Re:Invalid class typecast


Hi Martijin,

Thanks for help!! :-)
The procedure was almost correct. I was using TBlobStream instead
TSQLBlobStream.

The BLR blob type was mencioned by Richard Gilbert in his message. I was
justing asking to him, how he did it.

Bye,

Rodrigo C. Souza.

Quote
"Martijn Tonies" <m.tonies@upscene!nospam!.com> wrote in message

news:3e8d2f20@newsgroups.borland.com...
Quote
> Hi,

> > procedure TForm1.Button1Click(Sender: TObject);
> > var
> >    MyBlobStream : TBlobStream;
> >    MyFileStream : TFileStream;
> > begin
> >   try
> >     SQLQuery1.Active:=true;

> > Error here>>>>    MyBlobStream :=
> > TBlobStream.Create(SQLQuery1.Fieldbyname('MyFileOnDataBase') as
TBlobField,
> > bmRead);

> Did you check the classtype of the field that comes back with FieldByName?
> (You can, amongst other ways, simply do this by:
> ShowMessage(SQLQuery1.FieldByName('MyFileOnDataBase').ClassName); )

> >     MyFileStream := TFileStream.Create('C:\temp_file.mp3', fmCreate or
> > fmOpenWrite);
> >     MyFileStream.CopyFrom(MyBlobStream, 0);
> >   finally
> >     MyFileStream.Free;
> >     MyBlobStream.Free;
> > end;
> > end;

> > On this table I'm saving some MP3 files. When I try to save the file
using
> > dbexpress (SQLQuery) I get the same error.
> > I think that I'm using the wrong class, Am I?

> > And I would like to complete my question asking to Richard Gilbert what
kind
> > of BLOB type is this BLR? I never saw this type of BLOB.

> BLR? How did you create this blob column? The pre-defined types are
> TEXT (1) and BINARY (0). In subtype 0 you can put anything you like
> (in 1 also, but hey - it's the standard). If you're using BLR, better not.

> --

> With regards,

> Martijn Tonies
> Database Workbench - the developer tool for InterBase & Firebird
> Upscene Productions
> http://www.upscene.com

> See you at the First European Firebird Conference in May in Fulda, Germany
> http://www.firebird-conference.com

Other Threads