Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to load a Unicode file into a TMemo Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
16-Mar-03
Category
Reporting /Printing
Language
Delphi 3.x
Views
69
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Lou Adler

Load a Unicode file into a TMemo

Answer:
1   
2   procedure LoadUnicodeFile(const filename: string; strings: TStrings);
3   
4     procedure SwapWideChars(p: PWideChar);
5     begin
6       while p^ <> #0000 do
7       begin
8         p^ := WideChar(Swap(Word(p^)));
9         Inc(p);
10      end;
11    end;
12  
13  var
14    ms: TMemoryStream;
15    wc: WideChar;
16    pWc: PWideChar;
17  begin
18    ms := TMemoryStream.Create;
19    try
20      ms.LoadFromFile(filename);
21      ms.Seek(0, soFromend);
22      wc := #0000;
23      ms.write(wc, sizeof(wc));
24      pWC := ms.Memory;
25      if pWc^ = #$FEFF then {normal byte order mark}
26        Inc(pWc)
27      else if pWc^ = #$FFFE then
28      begin {byte order is big-endian}
29        SwapWideChars(pWc);
30        Inc(pWc);
31      end
32      else
33        ; {no byte order mark}
34      strings.Text := WideChartoString(pWc);
35    finally
36      ms.free;
37    end;
38  end;
39  
40  //Used like this:
41  
42  LoadUnicodeFile(filename, memo1.lines);


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC