[fpc-devel] Unicode support - for the 20th time... ;-)
skalogryz.lists at gmail.com
Thu Nov 20 13:29:43 CET 2008
if the matter is only loading text from file, why don't you write your
own utility function to load files content. After text is loaded from
file, you could process them as WideStrings.
That's the way i'm doing. Since LCL handles UTF8 strings I always
encode widestrings for LCL components, but for internal processing i
For easy of use, i've written utility function, so loaded files (or
streams) are first checked if they're unicode. Unicode text are then
converted to required format (UTF8 or UTF16). See the attached unit.
procedure TForm1.Button1Click(Sender: TObject);
if OpenDialog1.Execute then
Memo1.Text := ReadTextFile(OpenDialog1.FileName, true);
// if file is UTF16 and utf16 mark is present, then ReadTextFile
will convert read WideString to the UTF8string
// if i need WideString first, i'd use ReadTextFileWide, that reads
WideString (so no additional converting is used if UTF16 file is read)
// but if file is UTF8 then ReadTextFileWide convert to UTF16.
procedure TForm1.Button2Click(Sender: TObject);
prc : TProcess;
prc := TProcess.Create(nil);
prc.Options := [poUsePipes, poStderrToOutPut];
prc.CommandLine := Edit1.Text;
Memo1.Text := ReadTextStreamWide(prc.Output);
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 2558 bytes
Desc: not available
More information about the fpc-devel