本例效果图
代码文件
unit Unit;
interface
uses
Windows Messages SysUtils Variants Classes Graphics Controls Forms
Dialogs StdCtrls;
type
TForm = class(TForm)
Button: TButton;
Memo: TMemo;
procedure ButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
end;
var
Form: TForm;
implementation
{$R *dfm}
procedure TFormButtonClick(Sender: TObject);
var
streamstream: TStringStream;
b: Byte;
bs: string;
begin
{建立第一个流 使用默认的双字节编码; 流中的数据是 Memo 中的字符串}
stream := TStringStreamCreate(MemoText );
{把第一个流的十六进制编码显示在 Memo 中}
bs := ;
for b in streamBytes do bs := Format(bs + %x );
MemoLinesAdd(bs);
{建立第二个流 用 UTF 编码; 还是基于第一个流中的字符串}
stream := TStringStreamCreate(streamDataString TEncodingUTF);
{把第二个流的十六进制编码显示在 Memo 中}
bs := ;
for b in streamBytes do bs := Format(bs + %x );
MemoLinesAdd(bs);
streamFree;
streamFree;
end;
procedure TFormFormCreate(Sender: TObject);
begin
MemoAlign := alTop;
MemoScrollBars := ssBoth;
MemoText := 万一的 Delphi 博客;
end;
end
窗体文件:
object Form: TForm
Left =
Top =
Caption = Form
ClientHeight =
ClientWidth =
Color = clBtnFace
FontCharset = DEFAULT_CHARSET
FontColor = clWindowText
FontHeight =
FontName = Tahoma
FontStyle = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch =
TextHeight =
object Button: TButton
Left =
Top =
Width =
Height =
Caption = Button
TabOrder =
OnClick = ButtonClick
end
object Memo: TMemo
Left =
Top =
Width =
Height =
LinesStrings = (
Memo)
TabOrder =
end
end