I'm sure you could probably do it with normal VCL objects, but would involve
TStreams of some sort and just wouldn't be as easy IMHO.
-BKN
"Guy" <n...@na.com> wrote in message news:44a3d65b$1...@newsgroups.borland.com...
I did it my self with the following function:
It works perfectly :-)
I dont understand why Borland didnt include Writeln/Readln for WideStrings.....
function THaaretz.WriteUnicodeFile(const fn: String): Boolean;
type
WideStringFile = file of Word;
procedure WritelnWideString(var f: WideStringFile; const st: WideString);
var
i: Integer;
w: Word;
begin
for i:=1 to Length(st) do
begin
w:=Word(st[i]);
Write(f,w);
end;
w:=$000D;Write(f,w);
w:=$000A;Write(f,w);
end;
var
i: Integer;
st: WideString;
f: WideStringFile;
w: Word;
begin
AssignFile(f,fn);rewrite(f);Result:=IOResult = 0;
if Result then
begin
w:=$FEFF;Write(f,w);
st:='<UNICODE-WIN>';
WritelnWideString(f,st);
for i:=0 to TheFile.Count-1 do
begin
st:=TheFile[i];
WritelnWideString(f,st);
end;
CloseFile(f);Result:=IOResult = 0;
end;
end;
It isn't very hard. I have sometimes problems with Using File of xyz which I didn't have
when using TFileStream direct.
> It works perfectly :-)
> I dont understand why Borland didnt include Writeln/Readln for WideStrings.....
You function have only one coding of Unicode. You didn't support Big-Endian (I think
your writing is only Little Endian) and Saving as UTF-8 with/without BOM.
>> It works perfectly :-)
>> I dont understand why Borland didnt include Writeln/Readln for WideStrings.....
>
>You function have only one coding of Unicode. You didn't support Big-Endian (I think
>your writing is only Little Endian) and Saving as UTF-8 with/without BOM.
DIUnicode writes (and reads!) WideStrings in more than 50 encodings natively,
(UTF-8, UTF-16 big and little endian, Windows & Mac encodings, etc.), and more
than 130 encodings when linked against DIConverters (Chinese, Japanese, and many
more).
DIUnicode download: http://www.yunqa.de/delphi/unicode/
Regards,
Ralf
---
The Delphi Inspiration
http://www.yunqa.de/delphi/
OpenXML (http://www.philo.de/xml/)also have Converting-Functions for many Encodings.
Ralph, do you have a sample project to illustrate how to read/write using
this product? It sounds great, but I cannot understand exactly how to link
it against DIConverters, and how then to use it. I'm maybe a little slow.
But an example program would be fantastic. THX
Using DIConverters to add even more encodings to DIUnicode does not require you
to change your code which uses the library, you just need set a compiler
directive (DIUnicode source code) or copy a few precompiled *.DCUs which access
DIConverters. The DIUnicode Help file desribes this in detail and I have copied
the relevant section to this message (see below).
If you have a specific question about DIUnicode, please feel free to contact me
via e-mail support.
Regards,
Ralf
---------------
From the DIUnicode Help file:
Extending DIUnicode with DIConverters
DIUnicode already supports more than 70 character encodings natively, but it is
additionally prepared to use the 130+ encodings of DIConverters.
Before you can use DIUnicode with the DIConverters encodings, you first need to
download the DIConverters package.
Next extract the package to any folder of your choice. Installation into the
Delphi IDE is not required, all you need to do is to set the Delphi search path
to where you extracted the DIConverters source files.
USE_DICONVERTERS conditional compiler define
Using DIConverters' encodings with DIUnicode is controlled by the
USE_DICONVERTERS conditional compiler directive, which you need to define for
your project.
Choose the Menu Project -> Options ... -> Tab Directories / Conditionals and add
USE_DICONVERTERS to the Conditional defines edit box.
For the source code version of DIUnicode, that's all there is to do. The next
time you rebuild your project, Delphi will automatically link your executable
against DIConverters.
To make sure that the change of compiler defines takes effect, a full rebuild of
your project (Menu Project -> Build) is usually required instead of a simple
make (which only recompiles source code which changed after the latest compile).
Using DIConverters with precompiled DIUnicode DCUs
Specially prepared precompiled DIUnicode DCUs are available which make it
possible to use DIConverters even without the DIUnicode source code.
These precompiled DCUs are located in a subfolder to the Delphi Version folder.
Simply copy the files from there to the Delphi Version folder - overriding the
existing files - , then rebuild your project as described above.
Don't forget to define the USE_DICONVERTERS compiler define for the precompiled
DCUs just like you would for the source code. This is required because parts of
the binary versions of DIUnicode are already distributed as source code.
---------------
"RHR" <rr...@neosoft.com> wrote:
---