program ParameterizedStringMethodTest;
{$APPTYPE CONSOLE}
type
TMyClass =
class
class procedure Test<T>(S: T);
end;
T1252String =
type AnsiString(1252);
class procedure TMyClass.Test<T>(S: T);
var
StringTypeInfo: Pointer;
begin
StringTypeInfo := TypeInfo(T);
if StringTypeInfo = TypeInfo(AnsiString)
then
WriteLn('
AnsiString: ' + AnsiString(Pointer(@S)^))
else
if StringTypeInfo = TypeInfo(RawByteString)
then
WriteLn('
RawByteString: ' + RawByteString(Pointer(@S)^))
else
if StringTypeInfo = TypeInfo(UnicodeString)
then
WriteLn('
UnicodeString: ' + UnicodeString(Pointer(@S)^))
else
if StringTypeInfo = TypeInfo(ShortString)
then
WriteLn('
ShortString: ' + ShortString(Pointer(@S)^))
else
if StringTypeInfo = TypeInfo(UTF8String)
then
WriteLn('
UTF8String: ' + UTF8String(Pointer(@S)^))
else
if StringTypeInfo = TypeInfo(T1252String)
then
WriteLn('
T1252String: ' + T1252String(Pointer(@S)^))
else
WriteLn('
Unknown type');
end;
begin
TMyClass.Test(AnsiString('
Ansi'));
TMyClass.Test(RawByteString('
Raw'));
TMyClass.Test(UnicodeString('
Uni'));
TMyClass.Test(
string('
string is Uni too'));
TMyClass.Test(ShortString('
Short'));
TMyClass.Test(UTF8String('
UTF8'));
TMyClass.Test(T1252String('
1252'));
ReadLn;
end.