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);