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中orm
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