Tiburon supports Unicode LoadFromFile and SaveToFile

Source: Internet
Author: User
In Tiburon, I can use Unicode characters in controls such as TMemo, TListBox, TComboBox (and other lists containing characters. How can we load and save strings from a file? What changes do I need to make in a program that has been written using Delphi and C ++ Builder to process Unicode characters for these components? The answer is as follows:

A new and optional parameter is displayed in the LoadFromFile and SaveToFile methods. The optional parameter name is "Encoding" and its type is "TEncoding ". TEncoding (this type is declared in the SysUtils unit) class properties, which can help you specify the loading or saving strings types: ASCII, BigEndianUnicode, Default, Unicode, UTF7, UTF8.

The following is the declaration of LoadFormFile and SaveToFile in controls containing the TStrings type (declared in the Classes unit ):

Delphi:
 Procedure TStrings. LoadFromFile (const FileName: string );
 Procedure TStrings. LoadFromFile (const FileName: string; Encoding: TEncoding );
 Procedure TStrings. SaveToFile (const FileName: string );
 Procedure TStrings. SaveToFile (const FileName: string; Encoding: TEncoding );

C ++ Builder:
 Virtual void _ fastcall LoadFromFile (const System: UnicodeString FileName );
 Virtual void _ fastcall LoadFromFile (const System: UnicodeString FileName, Sysutils: TEncoding * Encoding );
 Virtual void _ fastcall SaveToFile (const System: UnicodeString FileName );
 Virtual void _ fastcall SaveToFile (const System: UnicodeString FileName, Sysutils: TEncoding * Encoding );

View the SaveToFile method of implementation in Delphi. You can see that TStream is used to save the strings with TEncoding information:

Procedure TStrings. SaveToFile (const FileName: string );
Begin
 SaveToFile (FileName, nil );
End;

Procedure TStrings. SaveToFile (const FileName: string; Encoding: TEncoding );
Var
 Stream: TStream;
Begin
 Stream: = tfilestream. Create (filename, fmcreate );
 Try
   Savetostream (stream, encoding );
 Finally
   Stream. Free;
 End;
End;

The following example shows how to use The ListBox control to load and save strings on your form:

Delphi:
  Listbox1.items. loadfromfile ('C: \ temp \ mylistboxitems.txt ', tencoding. utf8)
  Listbox1.items.savetofile('mylistboxitems.txt ', tencoding. utf8 );

C ++ builder:
  Listbox1-> items-> loadfromfile ("C: \ temp \ mylistboxitems.txt", tencoding: utf8 );
  Listbox1-> items-> savetofile ("C: \ temp \ mylistboxitems.txt", tencoding: utf8 );

Here is the screen of the above Delphi example program:

Using Tiburon, now my Delphi and C ++ demo programs can use uincode characters on the list box, edit box, and label, and I can also read and write Unicode strings directly on the hard disk.

Address: http://blogs.codegear.com/davidi/2008/07/15/38898/

Translation: Yu feiying

Reprinted please indicate the source!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.