Closed GoogleCodeExporter closed 9 years ago
1. Okay, function CharSetToCodePage(ACharSet: String): TBuffCodePage; will be
back soon.
2.
a) Do not convert a correct WideString like TntMemo1.Text. It can only become
erroneous. The TBuffString & CodePage versions of Create and Convert are only
useful, if you have loaded an unconverted stream/file into a WideString, which
might happen via TStrings.LoadFromStream()/TStrings.LoadFromFile().
b) In Unit1.dfm there are Unicode characters for Memo1.Text. This is not
correct and in my environment (my default charset is not RUSSIAN_CHARSET) they
are converted to lots of '?'.
c) You should use files (via TFileStream) for testing, because they are not
interpreted by Delphi like Unit1.dfm.
OrphanCat
Original comment by OrphanCat
on 12 Oct 2012 at 9:42
Well, an example of altered using a separate file and load "LoadFromFile".
Output parameter is TTNTStringList WideString. Even so, there is no conversion.
In the method of "Convert" function "MultiByteToWideChar" is not involved, it
should. Recoding is correct on the buttons "Create Byte Ansi (WideSrting)",
"Convert AnsiString as Byte", "Create Byte AnsiSrting". I want to make the
correct conversion of a line, not a file. Problems do not have encoded on a
computer, with an example. I specifically picked encoding "KOI8-R" and
Cyrillic, in other encodings are not visible. Additionally video if you have
something not correctly displayed.
P.S. The system does not add attachments, send an e-mail.
Original comment by SchwarzK...@yandex.ru
on 12 Oct 2012 at 4:41
After fixing an error in HtmlBuffer, that refused to set the CodePage for
converting from TBuffString and fixing some errors in Unit1.pas all buttons
produce results, which seem to be correct:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, HTMLUn2, HtmlView, StdCtrls, TntStdCtrls, HtmlBuffer, TntClasses;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
HtmlViewer1: THtmlViewer;
Button5: TButton;
Button6: TButton;
Button7: TButton;
Button8: TButton;
Button9: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure Button9Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var ConvHTML: WideString;
STL: TTNTStringList;
begin
STL := TTNTStringList.Create;
try
HTMLViewer1.Clear;
STL.LoadFromFile('1.txt');
ConvHTML := TBuffer.Convert(STL.Text, 20866);
HTMLViewer1.LoadFromString(ConvHTML);
finally
STL.Free;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var ConvHTML: WideString;
STL: TTNTStringList;
begin
STL := TTNTStringList.Create;
try
HTMLViewer1.Clear;
STL.LoadFromFile('1.txt');
ConvHTML := TBuffer.Convert(@STL.Text[1], Length(STL.Text) * sizeof(STL.Text[1]), 20866, CP_UTF16LE);
HTMLViewer1.LoadFromString(ConvHTML);
finally
STL.Free;
end;
end;
procedure TForm1.Button5Click(Sender: TObject);
var HTMLBuffer: TBuffer;
ConvHTML: WideString;
STL: TTNTStringList;
begin
STL := TTNTStringList.Create;
try
HTMLViewer1.Clear;
STL.LoadFromFile('1.txt');
HTMLBuffer := TBuffer.Create(STL.Text, 20866);
try
if HTMLBuffer <> nil then
begin
ConvHTML := HTMLBuffer.AsString;
end;
finally
if HTMLBuffer <> nil then
HTMLBuffer.Free;
end;
HTMLViewer1.LoadFromString(ConvHTML);
finally
STL.Free;
end;
end;
procedure TForm1.Button7Click(Sender: TObject);
var HTMLBuffer: TBuffer;
ConvHTML: WideString;
STL: TTNTStringList;
begin
STL := TTNTStringList.Create;
try
HTMLViewer1.Clear;
STL.LoadFromFile('1.txt');
HTMLBuffer := TBuffer.Create(@STL.Text[1], Length(STL.Text) * sizeof(STL.Text[1]), 20866, CP_UTF16LE);
try
if HTMLBuffer <> nil then
begin
HTMLBuffer.CodePage := 20866;
ConvHTML := HTMLBuffer.AsString;
end;
finally
if HTMLBuffer <> nil then
HTMLBuffer.Free;
end;
HTMLViewer1.LoadFromString(ConvHTML);
finally
STL.Free;
end;
end;
procedure TForm1.Button8Click(Sender: TObject);
var HTMLBuffer: TBuffer;
ConvHTML: WideString;
STL: TTNTStringList;
begin
STL := TTNTStringList.Create;
try
HTMLViewer1.Clear;
STL.LoadFromFile('1.txt');
HTMLBuffer := TBuffer.Create((@AnsiString(STL.Text)[1]), Length(STL.Text), 20866);
try
if HTMLBuffer <> nil then
begin
HTMLBuffer.CodePage := 20866;
ConvHTML := HTMLBuffer.AsString;
end;
finally
if HTMLBuffer <> nil then
HTMLBuffer.Free;
end;
HTMLViewer1.LoadFromString(ConvHTML);
finally
STL.Free;
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
var ConvHTML: WideString;
STL: TStringList;
begin
STL := TStringList.Create;
try
HTMLViewer1.Clear;
STL.LoadFromFile('1.txt');
ConvHTML := TBuffer.Convert(STL.Text, 20866);
HTMLViewer1.LoadFromString(ConvHTML);
finally
STL.Free;
end;
end;
procedure TForm1.Button4Click(Sender: TObject);
var ConvHTML: WideString;
STL: TStringList;
begin
STL := TStringList.Create;
try
HTMLViewer1.Clear;
STL.LoadFromFile('1.txt');
ConvHTML := TBuffer.Convert(@STL.Text[1], Length(STL.Text), 20866);
HTMLViewer1.LoadFromString(ConvHTML);
finally
STL.Free;
end;
end;
procedure TForm1.Button6Click(Sender: TObject);
var HTMLBuffer: TBuffer;
ConvHTML: WideString;
STL: TStringList;
begin
STL := TStringList.Create;
try
HTMLViewer1.Clear;
STL.LoadFromFile('1.txt');
HTMLBuffer := TBuffer.Create(STL.Text, 20866);
try
ConvHTML := HTMLBuffer.AsString;
finally
HTMLBuffer.Free;
end;
HTMLViewer1.LoadFromString(ConvHTML);
finally
STL.Free;
end;
end;
procedure TForm1.Button9Click(Sender: TObject);
var HTMLBuffer: TBuffer;
ConvHTML: WideString;
STL: TStringList;
begin
STL := TStringList.Create;
try
HTMLViewer1.Clear;
STL.LoadFromFile('1.txt');
HTMLBuffer := TBuffer.Create(@STL.Text[1], Length(STL.Text), 20866);
try
if HTMLBuffer <> nil then
begin
HTMLBuffer.CodePage := 20866;
ConvHTML := HTMLBuffer.AsString;
end;
finally
if HTMLBuffer <> nil then
HTMLBuffer.Free;
end;
HTMLViewer1.LoadFromString(ConvHTML);
finally
STL.Free;
end;
end;
end.
Original comment by OrphanCat
on 13 Oct 2012 at 12:38
After the last update function TBuffer stopped behaving inappropriately. But
the function of working with WideString is only
TBuffer.Create((@AnsiString(STL.Text)[1]), Length(STL.Text),
TBuffer.Convert(@STL.Text[1], Length(STL.Text),
TBuffer.Create(@STL.Text[1], Length(STL.Text),
I think @AnsiString(STL.Text)[1] does not do right.
Get the text after conversion should be:
1234567890
`~!@"#№$;%^:&?*()-_=+\|/<>,.[{]}
абвгдеёжзиклмнопрстуфхцчшщъюьэюя
АБВГДЕЁЖЗИКЛМНОПРСТУФХЦЧШЩЪЮЬЭЮЯ
abcdefghijklmopqrstuvxyz
ABCDEFGHIJKLMOPQRSTUVXYZ
For added clarity, the example of the Korean character set.
A conversion to other encoding same-given sense.
Example:
http://rghost.ru/40946767
Original comment by SchwarzK...@yandex.ru
on 15 Oct 2012 at 8:40
Original issue reported on code.google.com by
SchwarzK...@yandex.ru
on 8 Feb 2012 at 5:09