Delphi 5的Bug?(0分)

  • 主题发起人 主题发起人 eloquent
  • 开始时间 开始时间
E

eloquent

Unregistered / Unconfirmed
GUEST, unregistred user!
调用Val('-132', I, Code)
返回的I=-132;
而调用Val('-132abc', I, Code);返回的I = 132;这是不是Delphi 5的一个Bug?
 
先检查Code<>0,判断val()是否正确返回
 
你看看Help

Val procedure

Converts a string to a numeric representation.

Unit

System

Category

string handling routines

procedure Val(S
var V
var Code: Integer);

Description

Val converts the string value S to its numeric representation,

as if it were read from a text file with Read.

S is a string-type expression
it must be a sequence of characters

that form a signed real number.

V is an integer-type or real-type variable. If V is an integer-type variable,

S must form a whole number.

Code is a variable of type Integer.

If the string is invalid, the index of the offending character is stored

in Code
otherwise, Code is set to zero. For a null-terminated string,

the error position returned in Code is one larger than the actual

zero-based index of the character in error.

Val performs range checking differently depending upon the setting

of the $R compiler directive and the type of the parameter V.

Setting Result

{$R+} An out-of-range value always generates a run-time error.
{$R-} The values for out-of-range vary depending upon the data type of V.
 
那么能否只转换S中有效的部分,而返回S中第一个无效的字符?
 

这是Delphi 5的一个Bug吗?

你要想转换一部分(可能好几个有效部分如:'123abc456'),
自己写个函数一个字符一个字符判断不就行了吗?
 
如果 VAL(str, int, err) 的 err <> 0, int 的值是没有意义的.
不是 BUG.
 
接受答案了.
 
后退
顶部