"Invalid class typecast" when loading stream from SQLite (delphi)

1

I'm trying to fetch an image I've already inserted into my SQlite database, however on the line

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

I have the error "Invalid class typecast"

note: I'm 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, at 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, as I created it as BLOB. If I find a solution I will post it here.

note: I did this to find the field type:

ShowMessage(query.FieldByName('imagem').ClassName);
    
asked by anonymous 20.01.2016 / 12:06

0 answers