再问:如何判断variant类型的值是否为空?(100分)

  • 主题发起人 冰冷的雨
  • 开始时间

冰冷的雨

Unregistered / Unconfirmed
GUEST, unregistred user!
代码如下:
(OnCodeBeforeScroll)
with DataSetdo
if VarIsEmpty(DieldByName('iCode').Value)
or VarIsEmpty(DieldByName('cText').Value) then
begin
ShowMessage('请输入代码');
abort;
end
else
ShowMessage(inttostr(FieldByName('iCode').Value)+' '
+FieldByName('iCode').Value;
为什么当cText没有内容时,两个ShowMessage都不执行,而iCode没有内容时会出错:Could not convert variant of type (Null) into
type (Integer)?
 
VarIsNull function
Empty 和 null不一样
应该VarIsNull来判断。数据库里值为Null时VarIsNull是有效的。
 
还可以这样判断
if not tb.FieldByName('iCode').IsNull then
begin
//do something
end;
 
那VarIsEmpty用于什么情况呢?
 
自己看源码,VarIsEmpty包括了VarIsNull的情况
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
962
SUNSTONE的Delphi笔记
S
S
回复
0
查看
784
SUNSTONE的Delphi笔记
S
S
回复
0
查看
569
SUNSTONE的Delphi笔记
S
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
顶部