"Invalid class Typecast" when loading stream from Sqlite (Delphi)

Asked

Viewed 297 times

1

I’m trying to find an image I’ve already entered in my Sqlite database, however on the line

ms:=query.CreateBlobStream(query.FieldByName('imagem'),TBlobStreamMode.bmRead);

have error "Invalid class Typecast"

note: I am using Delphi-xe8;

Here is my code:

    Procedure Tform33.LoadFromSQLiteBlobArt;
       var
              ms:TStream;
              BlobField:Tblobfield;
              i:integer;
            begin
           try
            query.SQL.Text:='SELECT imagem From Artigos where Imagem>0;';
            query.open;
             query.First;
              num_regs_fb_art:=0;
               while not query.Eof do
                 begin
                  i:=i+1;
                   try

                     query.MaxBlobSize:=100;
                     BinaryAsBITMap[i]:=Tbitmap.create;
                     ms:=TMemoryStream.create;

                     query.FieldByName('imagem').SetFieldType(ftBlob);

                     ms.Seek(0,soFromBeginning);

                //ms:=query.CreateBlobStream(query.FieldByName('imagem'),bmRead);
         ms:=query.CreateBlobStream(query.FieldByName('imagem'),TBlobStreamMode.bmRead);
                     BinaryAsBITMap[i].LoadFromStream(ms);

                     image1.Bitmap:=BinaryAsBITMap[i];

                   finally
                     ms.Free;
                   end;
                  query.Next;
                  end;
             except
             on e:exception do
             showmessage(e.Message);
             end;
             query.Close;
           end;

I found where the error was, the end the problem was not the code. The field itself in the database is of type Largeint. Because it is as referred is a mystery, because I created it as BLOB. If I find a solution I will post here.

note: I did it to find out the type of the field:

ShowMessage(query.FieldByName('imagem').ClassName);
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.