Forum > General

error in debug when using dbimage

(1/2) > >>

mangakissa:
I'm converting my delphi demo to lazarus 1.44 linux (mint). In a form I load an image from a database. In debug mode this will occur an error. But the application goes on and there's is no AV. So everything works fine (at the moment).

Did I notised a bug?

My resources are:
- linux
  RELEASE=17.1
  CODENAME=rebecca
  EDITION="MATE 64-bit"
  DESCRIPTION="Linux Mint 17.1 Rebecca"
  DESKTOP=MATE
  TOOLKIT=GTK
- Lazarus 1.4.4 / FPC 2.6.4
- embedded firebird 2.5
- ZEOS 7.1X

rvk:
How was the image saved to the database?

If it was saved as raw image and not using TDBImage but using BlobStream for example you can't just read the image via TDBImage. Default the TDBImage writes the extension before the image (if the WriteHeader is set to true).

If the image is saved without the extension in front of it you need to implement the OnDBImageRead to return the correct extension of the image (.jpg/.bmp etc).

If the image was written with TDBImage are you sure the WriteHeader was set to true at the time?

mangakissa:
I don't know. It's the same database I'm using the same database with Delphi XE7. As far as I know the image is written with DBImage with ZEOS. What do you mean with WriteHeader?

rvk:

--- Quote from: mangakissa on November 02, 2015, 12:31:45 pm ---What do you mean with WriteHeader?

--- End quote ---
In Lazarus there is a header written before the actual image. The header contains the extension of the image (jpg/bmp/png etc) so the component knows what kind of image it is. The WriteHeader is true by default so in Lazarus the TDBImage writes this string before the actual data by default. For reading the WriteHeader is not used.

When reading data from the database the TDBImage looks if you implemented TDBImage.OnDBImageRead. If you did you need to provide the GraphExt-parameter with the correct image-type. After that TDBImage reads the image raw from the database. If you didn't implement TDBImage.OnDBImageRead then TDBImage expects the GraphExt-string to be part of the actual data in the database.

Related code:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TDBImage.LoadPicture;...        try          AGraphic := nil;          GraphExt := '';          if assigned(FOnDBImageRead) then            begin            // External method to identify graphic type            // returns file extension for graphic type (e.g. jpg)            // If user implements OnDBImageRead, the control assumes that            // the programmer either:            //            // -- Returns a valid identifier that matches a graphic class and            //    the remainder of stream contains the image data. An instance of            //    of graphic class will be used to load the image data.            // or            // -- Returns an invalid identifier that doesn't match a graphic class            //    and the remainder of stream contains the image data. The control            //    will try to load the image trying to identify the format            //    by it's content            //            // In particular, returning an invalid identifier while the stream has            // a image header will not work.            OnDBImageRead(self,s,GraphExt);            GraphExtToClass;            end          else            ReadImageHeader;
I don't think you wrote the extension in Delphi before the image. I don't think the TDBImage in Delphi has this extension capability. So, to keep it compatible, you need to implement that OnDBImageRead and provide the GraphExt. And when writing the image back to the database you need to set WriteHeader to false.

Only thing is that you need to provide the GraphExt and if you don't know which type is saved then you don't know what to provide. But you had the same trouble in Delphi :)

If the image is always jpg that isn't really a problem.

taazz:

--- Quote from: rvk on November 02, 2015, 12:41:27 pm ---
--- Quote from: mangakissa on November 02, 2015, 12:31:45 pm ---What do you mean with WriteHeader?

--- End quote ---
In Lazarus there is a header written before the actual image. The header contains the extension of the image (jpg/bmp/png etc) so the component knows what kind of image it is.
--- End quote ---
which makes it delphi compatible.

Navigation

[0] Message Index

[#] Next page

Go to full version