繁体   English   中英

不兼容的类型:widestring和tintegerfield

[英]incompatible types: widestring and tintegerfield

有人知道这会发生什么吗?

我已将所有数据库对象声明为整数,并将我的数据集对象声明为整数

当我运行ado查询时,我会从此处获取值,即尝试将其分配给也声明为整数的数据集。 但是它一直在给我

不兼容的类型:widestring和tintegerfield

这是确切的代码:

dxMemData1.FieldByName(dxMemData1RetailCalendarPeriodID) := 
  adoTreeWindow.FieldByName('RetailCalendarPeriodID').AsIntege‌​r;

dxMemData1.FieldByName(dxMemData1RetailCalendarPeriodID):= adoTreeWindow.FieldByName('RetailCalendarPeriodID')。AsIntege‌r

不应该编译。

看起来dxMemData1RetailCalendarPeriodID是您在dxMemData1数据集上创建的持久字段对象。 FieldByName方法用于按名称查找字段,但是您不需要这样做,因为您已经拥有 dxMemData1RetailCalendarPeriodID字段!

所以,您需要的只是

dxMemData1RetailCalendarPeriodID.AsInteger := adoTreeWindow.FieldByName('RetailCalendarPeriodID').AsIntege‌​r

发生编译器错误的原因是, FieldByName希望传递一个给出字段名称的字符串,而您试图传递该字段本身,这是TObject的后代而不是字符串。 以下代码本来可以工作,但由于已经显示了代码,因此不必要:

dxMemData1.FieldByName(dxMemData1RetailCalendarPeriodID.FieldName) := adoTreeWindow.FieldByName('RetailCalendarPeriodID').AsIntege‌​r;

更新您说您收到“无效的变量操作”错误。 如果使用以下代码,您是否仍然得到它:

if not adoTreeWindow.FieldByName('RetailCalendarPeriodID').IsNull then    
  dxMemData1RetailCalendarPeriodID.AsInteger := adoTreeWindow.FieldByName('RetailCalendarPeriodID').AsIntege‌​r

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM