pascal中val函数code是做什么的
发布网友
发布时间:2022-05-02 13:58
我来回答
共4个回答
热心网友
时间:2022-06-20 09:19
val是把字符川变成整型的数的
比如val('1234',a,k);
那么a就变成了1234的整型
当然那个a是integer
k也是integer
k是用来交换的,可以用其他的代替
热心网友
时间:2022-06-20 09:20
返回出错码
如:val('123a',a,b);
运行后b<>0
热心网友
时间:2022-06-20 09:20
Delphi syntax:
procere 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 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 runtime error.
{$R-} The values for out-of-range vary depending upon the data type of V.
Example:
uses Dialogs;
var
I, Code: Integer;
begin
{ Get text from TEdit control }
Val(Edit1.Text, I, Code);
{ Error ring conversion to integer? }
if Code <> 0 then
MessageDlg('Error at position: ' + IntToStr(Code), mtWarning, [mbOk], 0, mbOk);
else
Canvas.TextOut(10, 10, 'Value = ' + IntToStr(I));
end;
热心网友
时间:2022-06-20 09:21
code是记录错误位置
比如
val('123a',i,code)
code就等于4
val('123',i,code)
code就等于0