Skip to content

Instantly share code, notes, and snippets.

@omonien
Created January 2, 2023 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save omonien/3a53e6b4747883db24d4b0bf4f573bf3 to your computer and use it in GitHub Desktop.
Save omonien/3a53e6b4747883db24d4b0bf4f573bf3 to your computer and use it in GitHub Desktop.
C# to Delphi by ChatGPT
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