AnsiString类型定义的时候可以直接指定代码页,比如950繁体字,936日文

procedure TForm3.FormCreate(Sender: TObject);
type
  AnsiStringForPage = type AnsiString(950);//代码页
var
  AnsiStr: AnsiStringForPage;
  i: Integer;

  function GetAnsiCharCode(Value: AnsiChar): string;
  begin
    Result := IntToHex(ord(Value), 2);
  end;

begin
  AnsiStr := 'abcABC中国人';//ansi兼容abcAbc,所以这些字母对应的值与代码页无关,而中国人,在950中人存在,国不存,所以长度为11,936时长度12,932也是长度11
  for i := 0 to Length(AnsiStr) do
    Memo1.Lines.Add(IntToHex(ord(AnsiStr[i]), 2));

以上内容只做学习标志,请勿查看

字符串赋值的时候会调用以下代码System.pas中

procedure _LStrLAsg(var Dest: _AnsiStr; const Source: _AnsiStr);//字符串复制
{$IFDEF PUREPASCAL}
var
  P: Pointer;
begin
  P := Pointer(Source);
  if P <> nil then
    _LStrAddRef(P);
  P := Pointer(Dest);
  Pointer(Dest) := Pointer(Source);
  _LStrClr(P);//清空字符串
end;
{$ELSE}
asm
        { ->    EAX     pointer to dest }
        {       EDX     source          }

        TEST    EDX,EDX
        JE      @@sourceDone
原文地址:https://www.cnblogs.com/ZhouXiHong/p/4422021.html