#1 2014-05-28 12:49:31

array81
Member
From: Italy
Registered: 2010-07-23
Posts: 411

SaveAsRawByteString problema

I need save an image into my database, for this I use this code:

SaveAsRawByteString(imgDocument.Picture,doc,gptJPG,80,1500);

ContattoRecord := TSQLContacts.Create;
try
  ContattoRecord.Name = "something";
  ContattoRecord.Lastname= "something";

  id := Database.Add(ContattoRecord, true);

  if id > 0 then
    begin
      Database.UpdateBlob(TSQLContacts, id, 'Document', doc)
    end;
finally
  ContattoRecord.Free;
end;

The image is not save into DB. I have check doc variable after SaveAsRawByteString with this code:

  MessageDlg(UTF8ToString(doc),mtError, mbOKCancel, 0);

IAnd I get always a black message.
I have use both BMP anf PNG like images for my test.

Any idea?

Offline

#2 2014-05-28 14:13:47

tech
Member
Registered: 2014-01-13
Posts: 107

Re: SaveAsRawByteString problema

I think that you've missed

SaveAsRawByteString(imgDocument.Picture,doc,gptJPG,80,1500);

ContattoRecord := TSQLContacts.Create;
try
  ContattoRecord.Name = "something";
  ContattoRecord.Lastname= "something";
  ContattoRecord.Document := doc;   <--------------------------------------
  id := Database.Add(ContattoRecord, true);

  if id > 0 then
    begin
      Database.UpdateBlob(TSQLContacts, id, 'Document', doc)
    end;
finally
  ContattoRecord.Free;
end;

Offline

#3 2014-05-28 20:34:33

array81
Member
From: Italy
Registered: 2010-07-23
Posts: 411

Re: SaveAsRawByteString problema

I don't use ForceBlobTransfert so I don't need set ContattoRecord.Document because Database.Add don't use it.

Offline

#4 2014-05-28 21:03:34

array81
Member
From: Italy
Registered: 2010-07-23
Posts: 411

Re: SaveAsRawByteString problema

I think I have found a possible problem: I don't have add this code to my unit:

initialization
  Gdip.RegisterPictures;

I'm remeber taht with this code in the pas my code works however on recent Delphi version (XE3 and XE6) if I add these line I get an error.
On Delphi XE6 I get
"Exception class EFilerError with message 'A class named TJpegImage already exists'" line 1081 of SynGdiPlus.pas

How can I fix it.

Offline

#5 2014-05-28 21:20:30

array81
Member
From: Italy
Registered: 2010-07-23
Posts: 411

Re: SaveAsRawByteString problema

If I comment this 2 lines of SynGdiPlus.pas (on Delphi XE6)

RegisterClass(TJpegImage);
RegisterClass(TPngImage);

all works. I thinks is need to add exceptions depending on the version of the compiler.

Offline

#6 2014-05-29 10:56:11

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,272
Website

Re: SaveAsRawByteString problema

Do not use Gdip.RegisterPictures if you do not need it.

You just have to initialize the GDI+ library, with:

Gdip := TGDIPlusFull.Create;

Offline

Board footer

Powered by FluxBB