pascal中val函数code是做什么的

来源:百度知道 编辑:UC知道 时间:2024/05/16 11:00:47

code是记录错误位置

比如
val('123a',i,code)
code就等于4

val('123',i,code)
code就等于0

val是把字符川变成整型的数的
比如val('1234',a,k);
那么a就变成了1234的整型
当然那个a是integer
k也是integer
k是用来交换的,可以用其他的代替

返回出错码
如:val('123a',a,b);
运行后b<>0

Delphi syntax:

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

Description

In Delphi code, 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 pos