Created
January 2, 2023 10:45
-
-
Save omonien/3a53e6b4747883db24d4b0bf4f573bf3 to your computer and use it in GitHub Desktop.
C# to Delphi by ChatGPT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
procedure PrintValue(const Value: TObject; const ValueType: TType); | |
var | |
TypeCode: TTypeCode; | |
TypeData: PTypeData; | |
TypeInfo: PTypeInfo; | |
begin | |
if Value = nil then | |
begin | |
WriteLn(ValueType); | |
Exit; | |
end; | |
TypeInfo := Value.ClassInfo; | |
TypeCode := TypeInfo.TypeData.OrdType; | |
case TypeCode of | |
Ord(TTypeCode.Int32): | |
WriteLn(Integer(Value)); | |
Ord(TTypeCode.Int64): | |
WriteLn(Int64(Value)); | |
Ord(TTypeCode.UInt32): | |
WriteLn(Cardinal(Value)); | |
Ord(TTypeCode.UInt64): | |
WriteLn(UInt64(Value)); | |
Ord(TTypeCode.Double): | |
WriteLn(Double(Value)); | |
Ord(TTypeCode.String): | |
WriteLn(String(Value)); | |
Ord(TTypeCode.Boolean): | |
WriteLn(Boolean(Value) or False); | |
Ord(TTypeCode.DateTime): | |
WriteLn(TDateTime(Value)); | |
Ord(TTypeCode.Object): | |
if GetTypeKind(TypeInfo) = tkClass then | |
begin | |
if Value is TBytes then | |
WriteLn(TBytes(Value)) | |
else if Value is TInt128 then | |
WriteLn(TInt128(Value)) | |
else if Value is TInt256 then | |
WriteLn(TInt256(Value)) | |
else if Value is IObject then | |
WriteLn(IObject(Value)) | |
else if GetTypeKind(TypeInfo) = tkEnumeration then | |
WriteLn(Cardinal(Value)); | |
end; | |
end; | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment