Val无法与UInt64一起使用? [英] Val does not work with UInt64?

查看:73
本文介绍了Val无法与UInt64一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很好奇以下代码为何无法将uint64值转换为字符串表示形式?

just curious why the following code fails to convert uint64 value in string representation ?

var
  num: UInt64;
  s: string;
  err: Integer;

begin
  s := '18446744073709551615';  // High(UInt64)
  Val(s, num, err);
  if err <> 0 then
    raise Exception.Create('Failed to convert UInt64 at ' + IntToStr(err));  // returns 20
end.

Delphi XE2

Delphi XE2

我错过了什么吗在这里?

Am I missing something here ?

推荐答案

根据文档


S是字符串类型的表达式;

S is a string-type expression; it must be a sequence of characters that form a signed real number.

我同意文档有些含糊;实际上, form 的确切含义以及一个带符号的实数的确切含义(尤其是如果 num

I agree the documentation is a bit vague; indeed, what exactly does form mean, and exactly what is meant by a signed real number (especially if num is an integer type)?

仍然,我认为要突出显示的部分是 signed 。在这种情况下,您需要一个整数,因此 S 必须是组成有符号整数的字符的序列。但是然后您的最大值是 High(Int64)= 9223372036854775807

Still, I think the part to highlight is signed. In this case, you want an integer, and so S must be a sequence of characters that form a signed integer. But then your maximum is High(Int64) = 9223372036854775807

这篇关于Val无法与UInt64一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆