TWideMemoField for a Blob Sub_Type 1 and SaveToFile problem

The forum for ZeosLib 7.2 Report problems. Ask for help, post proposals for the new version and Zeoslib 7.2 features here. This is a forum that will be edited once the 7.2.x version goes into RC/stable!!

My personal intention for 7.2 is to speed up the internals as optimal a possible for all IDE's. Hope you can help?! Have fun with testing 7.2
Post Reply
louis
Expert Boarder
Expert Boarder
Posts: 107
Joined: 02.01.2009, 19:41

TWideMemoField for a Blob Sub_Type 1 and SaveToFile problem

Post by louis »

Hello,
I use Delphi 2010 and I have a Firebird 2.5 Database and a table as:

Code: Select all

CREATE TABLE DOC_FE
(
  ID Integer NOT NULL,
  XML Blob sub_type 1,
  CONSTRAINT DOC_FE_PK PRIMARY KEY (ID)
);
The Field XML contain a xml file like this:

Code: Select all

<?xml version="1.0" encoding="Windows-1252" standalone="no"?>
but if I try to save the field as:

Code: Select all

DOC_FExml.SaveToFile(AFileName);
the file AFileName contain:

Code: Select all

< ? x m l   v e r s i o n = " 1 . 0 "   e n c o d i n g = " W i n d o w s - 1 2 5 2 "   s t a n d a l o n e = " n o " ? > 
if I try to save as:

Code: Select all

Xml := TStringList.Create;
Xml.Text := DOC_FEXML.AsString;
Xml.SaveToFile(AFileName);
the file AFileName contains as expected:

Code: Select all

<?xml version="1.0" encoding="Windows-1252" standalone="no"?>
What I wrong?

Thanks
Last edited by louis on 05.02.2019, 15:37, edited 3 times in total.
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1939
Joined: 17.01.2011, 14:17

Re: TWideMemoField for a Blob Sub_Type 1 and SaveToFile problem

Post by marsupilami »

Hello louis,

on a first glance it looks like xml.SaveToFile(AFileName); saves the contents without an UTF-16 BOM and so your Editor doesn't know how to correctly read the file. Could you check that with some kind of an hex editor / viewer? This might be a bug in Delphi.

Best regards,

Jan
louis
Expert Boarder
Expert Boarder
Posts: 107
Joined: 02.01.2009, 19:41

Re: TWideMemoField for a Blob Sub_Type 1 and SaveToFile problem

Post by louis »

Hello,
marsupilami wrote:Could you check that with some kind of an hex editor / viewer? This might be a bug in Delphi.
with an hex viewer, in a file created by BlobField.SaveToFile, I get:

Code: Select all

3c 00 3f 00 78 00 6d 00 6c 00 20 00 76 00 65 00 <.?.x.m.l. .v.e.
but with an hex viewer I get in a right file (created by TStringList.SaveToFile):

Code: Select all

3c 3f 78 6d 6c 20 76 65 72 73 69 6f 6e 3d 22 31 <?xml version="1
Can I set anything to a BlobFile to SaveToFile in right mode?

Thanks.
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1939
Joined: 17.01.2011, 14:17

Re: TWideMemoField for a Blob Sub_Type 1 and SaveToFile problem

Post by marsupilami »

Hello Louis,

the problem here is that both components behabe as expected. TWideStringField is a delphi supplied class where we can't modify its behaviour. Zeos only uses it. TWideStringField uses UTF-16 internally so an encoding with 0x00-Bytes is expected there.

TStringList on the other hand is specified to use your ANSI-Encoding for saving its contents to files on disk. My Suggestion is to do something like this:

Code: Select all

var
  List: TStringList;
begin
  // some code here...
  
  List := TStringList.Create;
  try
    List.Text := MyZQuery.FieldByName('MyBlobTextField').AsString;
    List.SaveToFile('MyFileName.xml') // This method also can take encodings as parameters afaik
  finally
    FreeAndNil(List);
  end;
  
  // some more code here...
end;
TStringList has options to select any encoding you want - at least if your Delphi uses Unicode (Delphi 2009 or later).

If you have an ancient version of Delphi that still uses ANSI you might want to set your Connection Character Set according to your ANSI-Codepage. In that case Zeos will switch from using TWideStringField and TWideMemoField to TStringField and TMemoField which use ANSI encodeing instead of Unicode internally.

Best regards,

Jan
User avatar
EgonHugeist
Zeos Project Manager
Zeos Project Manager
Posts: 1936
Joined: 31.03.2011, 22:38

Re: TWideMemoField for a Blob Sub_Type 1 and SaveToFile problem

Post by EgonHugeist »

Hi Louis,

that indeed is a problem. To be cleare the TBlobStream has no virtual function we can override to get your problem resolved.
IMHO the only way to write raw encoded files is the way you did it.
Best regards, Michael

You want to help? http://zeoslib.sourceforge.net/viewtopic.php?f=4&t=3671
You found a (possible) bug? Use the new bugtracker dude! http://sourceforge.net/p/zeoslib/tickets/

Image
Post Reply