gpt4 book ai didi

delphi - Cardinal 到 OleVariant 的错误转换。 UInt64 没问题

转载 作者:行者123 更新时间:2023-12-03 15:51:24 26 4
gpt4 key购买 nike

program UInt32ToVariant;

uses
Vcl.Dialogs, System.SysUtils, System.Variants;

var
ui32Val: Cardinal;
si64Val: Int64;
ui64Val: UInt64;
v1: Variant;
v2: OleVariant;
sb: TStringBuilder;

begin
sb := TStringBuilder.Create();
try
ui32Val := 4234687430;
si64Val := Int64.MaxValue;
ui64Val := UInt64.MaxValue;

v1 := ui32Val;
v2 := ui32Val;
sb.AppendLine('Unsigned 32 bit integer:'#9 + Cardinal.ToString(ui32Val));
sb.AppendLine(#9'to Variant:'#9 + VarToStr(v1));
sb.AppendLine(#9'to OleVariant:'#9 + VarToStr(v2));
sb.AppendLine();

v1 := si64Val;
v2 := si64Val;
sb.AppendLine('Signed 64 bit integer:'#9 + Int64.ToString(si64Val));
sb.AppendLine(#9'to Variant:'#9 + VarToStr(v1));
sb.AppendLine(#9'to OleVariant:'#9 + VarToStr(v2));
sb.AppendLine();

v1 := ui64Val;
v2 := ui64Val;
sb.AppendLine('Unsigned 64 bit integer:'#9 + UInt64.ToString(ui64Val));
sb.AppendLine(#9'to Variant:'#9 + VarToStr(v1));
sb.AppendLine(#9'to OleVariant:'#9 + VarToStr(v2));

ShowMessage(sb.ToString());
finally
sb.Free();
end;
end.

结果是:

Unsigned 32 bit integer:    4234687430
to Variant: 4234687430
to OleVariant: -60279866 (Wrong!)

Signed 64 bit integer: 9223372036854775807
to Variant: 9223372036854775807
to OleVariant: 9223372036854775807

Unsigned 64 bit integer: 18446744073709551615
to Variant: 18446744073709551615
to OleVariant: 18446744073709551615 (Correct again!)

这真的是 Delphi 中的错误还是我做错了什么?

我可以假设 OleVariant 根本不支持无符号整数,但支持无符号 64 位整数,而不支持 32 位整数。

最佳答案

这是一个 Delphi 错误。

报告为 RSP-18363 Incorrect Conversion Cardinal to OleVariant

错误描述:

Incorrect direct conversion of the Cardinal to OleVariant. The result differs from the transformation of the Cardinal into the Variant into the OleVariant

关于delphi - Cardinal 到 OleVariant 的错误转换。 UInt64 没问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56109513/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com