Как загрузить юникоды в мемо? |
Previous Top Next |
Code: |
procedure LoadUnicodeFile(const filename: string; strings: TStrings);
procedure SwapWideChars(p: PWideChar); begin while p^ <> #0000 do begin p^ := WideChar(Swap(Word(p^))); Inc(p); end; end;
var ms: TMemoryStream; wc: WideChar; pWc: PWideChar; begin ms := TMemoryStream.Create; try ms.LoadFromFile(filename); ms.Seek(0, soFromend); wc := #0000; ms.Write(wc, sizeof(wc)); pWC := ms.Memory; if pWc^ = #$FEFF then {normal byte order mark} Inc(pWc) else if pWc^ = #$FFFE then begin {byte order is big-endian} SwapWideChars(pWc); Inc(pWc); end else ; {no byte order mark} strings.Text := WideChartoString(pWc); finally ms.free; end; end; |
Использовать
LoadUnicodeFile(filename, memo1.lines);
©Drkb::00555
Взято с Delphi Knowledge Base: http://www.baltsoft.com/