在 Delphi 2009 中:
string = UnicodeString; (同样: PString = PUnicodeString;)
Char = WideChar; (同样: PChar = PWideChar;)
本例效果图:
代码文件:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
Button7: TButton;
procedure FormCreate(Sender: TObject);
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);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
Memo1.Clear;
Edit1.Alignment := taCenter;
Edit1.Text := '''万一的 Delphi 博客''';
Button1.Caption := 'string';
Button2.Caption := 'AnsiString';
Button3.Caption := 'WideString';
Button4.Caption := 'Char';
Button5.Caption := 'AnsiChar';
Button6.Caption := 'WideChar';
Button7.Caption := '清' + #10#10 + '空';
Button7.WordWrap := True;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
str: string;
i: Integer;
begin
str := Edit1.Text;
Memo1.Clear;
for i := 1 to Length(str) do Memo1.Lines.Add(str[i]);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
str: AnsiString;
i: Integer;
begin
str := Edit1.Text;
Memo1.Clear;
for i := 1 to Length(str) do Memo1.Lines.Add(str[i]);
end;
procedure TForm1.Button3Click(Sender: TObject);
var
str: WideString;
i: Integer;
begin
str := Edit1.Text;
Memo1.Clear;
for i := 1 to Length(str) do Memo1.Lines.Add(str[i]);
end;
procedure TForm1.Button4Click(Sender: TObject);
var
c: Char;
begin
Memo1.Clear;
for c in Edit1.Text do Memo1.Lines.Add(c);
end;
procedure TForm1.Button5Click(Sender: TObject);
var
c: AnsiChar;
begin
Memo1.Clear;
for c in AnsiString(Edit1.Text) do Memo1.Lines.Add(c);
end;
procedure TForm1.Button6Click(Sender: TObject);
var
c: WideChar;
begin
Memo1.Clear;
for c in Edit1.Text do Memo1.Lines.Add(c);
end;
procedure TForm1.Button7Click(Sender: TObject);
begin
Memo1.Clear;
end;
end.