Read Unicode text files using memo-Reply to "ahgan"

Source: Internet
Author: User
Problem Source: http://www.cnblogs.com/del/archive/2008/05/29/1005631.html#1212654
First, this problem may not exist when it reaches Delphi 2008, because tstrings certainly supports Unicode at that time; the current version is 2007.
 
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs; Type tform1 = Class (tform) memo1: tmemo; Procedure formcreate (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} procedure tform1.formcreate (Sender: tobject); var stream: tmemorystream; PwC: pwidechar; begin stream: = tmemorystream. create; stream. loadfromfile ('C: \ temp \ unicode.txt '); PwC: = stream. memory; // Inc (PWC); {the starting byte may contain garbled characters, so you can remove} memo1.lines. text: = PwC; stream. free; end.

  

Form of a function:

 unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls; Type tform1 = Class (tform) memo1: tmemo; Procedure formcreate (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} // function for opening Unicode text files: function loadunicodetxt (F: string): ansistring; var stream: tmemorystream; P: pwidechar; begin result: = ''; if not fileexists (f) Then exit; stream: = tmemorystream. create; stream. loadfromfile (f); P: = stream. memory; Inc (p); Result: = P; stream. free; end; // call test: Procedure tform1.formcreate (Sender: tobject); var STR: string; begin STR: = loadunicodetxt ('C: \ temp \ unicode.txt '); memo1.clear; memo1.lines. add (STR); end.

   

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.