Sep 12

Untuk meload nilai file widestring (Unicode) agar bisa dikenali secara string, kita bisa menambahkan  procedure sebagai berikut ini :
[code lang="Delphi"]
(*
Following routines were originally posted by
Peter Below (TeamB)
*)

//Load a unicode file into a stringlist

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; { While }
End; { SwapWideChars }
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 { If }
Else;  // no byte order mark
strings.Text := WideChartoString( pWc );
finally
ms.free;
end;
End;
[/code]
Gunakan memo sejenisnya untuk menampung nilai string dari variabel.

contoh :

LoadUnicodeFile(filename, memo1.lines);

Popularity: 7% [?]

Post a comment


Masukkan Code ini K1-5YB5C6-C
untuk berbelanja di KutuKutuBuku.com