当数据集值为空时,delphi中AsInteger的值是什么? [英] What is the value from AsInteger in delphi when dataset value is null?
问题描述
我在delphi中有以下代码:
I have this code in delphi:
var_beg := MyQry.FieldByName('x_beg').AsInteger;
var_end := MyQry.FieldByName('x_end').AsInteger;
x_segment := copy(name, var_beg, var_end - var_beg);
现在,表中的 x_beg
和 x_end
列均可为空,并且在某些行上包含空值.我的问题是,当 x_beg
和 x_end
列为空时,变量 var_beg
和 var_end
会得到什么值?/p>
Now, in the table the columns x_beg
and x_end
are both nullable, and contain null values on some rows. My question is what values do the variables var_beg
and var_end
get when the columns x_beg
and x_end
are null?
推荐答案
Null由 AsInteger
函数自动转换为0(对于我尝试过的所有数据集组件都是如此,但使用不同的行为可能会有不同的行为 TField
的后代).
Null is automatically converted to 0 by AsInteger
function (It's true for all dataset components I tried but you could have different behaviors using different TField
's descendants).
如文档所述,:
使用AsInteger将字段数据的值读取为整数,或为该字段的内容分配一个整数值.田野不支持整数值,并且在尝试获取或设置AsInteger属性.
Use AsInteger to read the value of the field's data into an integer, or to assign an integer value to the contents of the field. TField does not support integer values, and raises an exception when an attempt is made to get or set the AsInteger property.
转换结果取决于对象是哪个 TField
后代类. TField.GetAsInteger
是一个虚拟函数,声明如下:
Conversion result depends on which TField
descendant class your object is.
TField.GetAsInteger
is a virtual function declared as follows:
function TField.GetAsInteger: Longint;
begin
raise AccessError('Integer'); { Do not localize }
end;
如果您需要检查该值是否为空,则可以使用:
If you need to check if the value is null you can use:
myField.AsVariant = Null
或
myField.IsNull
这篇关于当数据集值为空时,delphi中AsInteger的值是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!