BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Saving and reading text files in UTF8 / Unicode?

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Internationalization
View previous topic :: View next topic  
Author Message
itibira
Guest





PostPosted: Fri Mar 03, 2006 7:03 am    Post subject: Saving and reading text files in UTF8 / Unicode? Reply with quote



Greetings,

i have an application in D7 that uses the TnTRichEdit component. This
component was originally a TRichEdit and i was able to save and read
standard (ASCII) text into a binary file. With the new TnTRichEdit, i
am able to copy and paste, for example, Chinese characters into the
RichEdit component and it works OK.

However, i now need to save the Chinese characters into the binary file
and then, later, reload the text into the TnTRichEdit. My code for the
original ASCII text save is:

procedure TMyForm.SaveRichEditTextFileClick(Sender: TObject);
var
i: Integer;
j: Byte;
dmyString: ShortString;
begin
...
if SaveDialog.Execute then
begin
AssignFile(MyTypeFile, FileName);
ReWrite(MyTypeFile,1);
{ .. do some blockwrites of other data...}
...
j := MyRichEdit.Lines.Count;
BlockWrite(MyTypeFile,j,sizeof(j));

for i := 0 to MyRichEdit.Lines.Count-1 do
begin
dmyString := MyRichEdit.Lines.Strings[i];
BlockWrite(MyTypeFile,dmyString,succ(length(dmyString)));
end;
...
{...do more blockwrites...}
...
CloseFile(MyTypeFile);
end;
end;

and for reading it is:

procedure TMyForm.OpenRichEditTextFile(FileName: string);
var
FileNameLength: Integer;
i: Integer;
j: Byte;
dmyString: ShortString;
SizeByte: Byte;
FileType: string;
begin
...
if FileExists(FileName) then
begin
MyRichEdit.PlainText := True;
MyRichEdit.Lines.Clear;
AssignFile(MyTypeFile, FName);
FileMode := fmOpenRead;
Reset(SpeakTypeFile,1);
...
{.. do some other blockreads...}
....
BlockRead(MyTypeFile,j,sizeof(j)); {number of text lines to
follow}
if j <>0 then
for i := 0 to j-1 do
begin
BlockRead(MyTypeFile,SizeByte,sizeof(SizeByte));
{Get length of string that follows}
SetLength(dmyString, SizeByte);
BlockRead(MyTypeFile,dmyString[1],SizeByte);
{Get the whole string at one go}
MyRichEdit.Lines.Add(dmyString);
end;
...
{... some more blockreads...}
CloseFile(MyTypeFile);
end;
end;

However, i have tried using WideString and AnsiString variables but
when i view the saved file in Word, all i see is boxes (i used to get
question marks (?) before i used the WideString variables)

i'm running D7 on a Win 2000 Pro system.

i am a complete newbie to Unicode, WideString, AnsiString, UTF8, etc.
and i'm wondering where i'm going wrong. To be honest, i'm completely
lost...

Can anyone please help? Can someone show an example of how to convert
my code to be able to read and save the Unicode strings?

Thanks to everyone in advance for any and all help on this.

Cheers.
Back to top
Riki Wiki
Guest





PostPosted: Sun Mar 05, 2006 3:03 am    Post subject: Re: Saving and reading text files in UTF8 / Unicode? Reply with quote



On 2 Mar 2006 22:42:00 -0800, itibira wrote:

Quote:
Thanks to everyone in advance for any and all help on this.

Hoi

This newsgroup do not officially exist, that is why there is so few
messages here. Rather use b.p.d.internationalization.win32. Further you
need to repost your message/question on the Borland news server to make
everybody see it.

Take a look here:
<http://tinyurl.com/8m5nw>
which links to
<http://delphi.wikicities.com/wiki/Delphi_Newsgroups>
Back to top
itibira
Guest





PostPosted: Sun Mar 05, 2006 6:03 am    Post subject: Re: Saving and reading text files in UTF8 / Unicode? Reply with quote



Hi Riki,

Thanks very much for the help. No wonder i wasn't getting anywhere....

i do appreciate your help.

Cheers.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Internationalization All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.