Hi,
Ok, I've found out what the problem is and I hope it helps others (the clue is on the documentation, but I just missed it).
The problem is that in Lazarus some header information is stored along with the image data, which is not done in Delphi.
In the latest stable release of Lazarus some extra functionality was added to make programming more compatible, and two event handlers were added to images.
These are OnDBImageRead and OnDBImageWrite.
If these are set the code works fine and doesn't error.
rom Lazarus documentation
TDBImage
Delphi compatible behaviour can now be set.
Lazarus TDBImage by default saves information about the file type before the image data. This allows seamless use of various file formats (.jpg, .bmp,...). Delphi does not save information about the file type.
To allow programmers to use TDBImage more flexibly, including supporting Delphi compatibility, two events to TDBImage were added:
TOnDBImageRead = procedure(Sender: TObject; S: TStream; var GraphExt : string) of object;
TOnDBImageWrite = procedure(Sender: TObject; S: TStream; GraphExt : string) of object;
If the first event is defined then it is called instead of TDBImage reading from the stream and must return the file extension as GraphExt. For example:
procedure TMyForm.TDBImageDBImageRead(Sender: TObject; S: TStream;
var GraphExt: string);
begin
GraphExt := 'jpg';
end;
can be used when the type of the image is always JPEG.
Similarly, if OnDBImageWrite is present then this is called instead of TDBImage writing the file extension to the start of the BLOB in the database. For example:
procedure TMyForm.PhotoDBImageWrite(Sender: TObject;
S: TStream; GraphExt: string);
begin
if GraphExt <> 'jpg' then
raise Exception.Create('Can only save a JPEG Image');
end;
also works for an implicit JPEG.
Hope this helps someone.
Thanks
Dave