1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
uses
SysUtils;
{ https://www.developpez.net/forums/d1732510/environnements-developpement/delphi/contribuez/ne-prenez-pieds-strings/#post9515065 }
type
TStringInfo = record
CodePage: Word;
CharSize: Word;
RefCount: Integer;
Length : Integer;
end;
procedure StringInfo(p: Pointer);
var
i: ^TStringInfo;
begin
i := p; // l'adresse du premier caractère
Dec(i); // remonter de SizeOf(TStringInfo) en mémoire
WriteLn(' CodePage = ', i^.CodePage);
WriteLn(' CharSize = ', i^.CharSize);
WriteLn(' RefCount = ', i^.RefCount);
WriteLn(' Length = ', i^.Length);
end;
var
s: string;
begin
s := 'é';
WriteLn(Length(s) = 1); // FALSE
StringInfo(pointer(s));
WriteLn(s);
SetCodePage(rawbytestring(s), 850, FALSE); // 850 ou GetOemCP de l'unité Windows
StringInfo(pointer(s));
WriteLn(s);
SetLength(s, 1);
s[1] := #130;
StringInfo(pointer(s));
WriteLn(s);
end. |
Partager