在uses单元加入Variants!
VarType function from Variants unit in Delphi 7
In Delphi 5, VarType function is declared in Systems unit. In Delphi 7, it is moved to Variants unit.
Declaration: property Values[const name: String]: Variant
My problem is the statement Values['fieldname']:= 0 gives problem and the statement Values['fieldname']:= StrToInt('0') seems to work.
The field in the table is an integer field.
The same thing happens with a float field, the statement Values['fieldname']:= 1 gives problem and the statement Values['fieldname']:= StrToFloat('1') seems to work.
Does the Variant need to be "informed" what datatype it is with the help of functions like StrToInt and StrToFloat?
Declaration: property Values[const name: String]: Variant
My problem is the statement Values['fieldname']:= 0 gives problem and the statement Values['fieldname']:= StrToInt('0') seems to work.
The field in the table is an integer field.
The same thing happens with a float field, the statement Values['fieldname']:= 1 gives problem and the statement Values['fieldname']:= StrToFloat('1') seems to work.
Does the Variant need to be "informed" what datatype it is with the help of functions like StrToInt and StrToFloat?
本文探讨了在 Delphi7 中使用 Variants 单元进行 VarType 函数操作的方法。作者指出,在 Delphi5 中 VarType 函数声明于 Systems 单元,而在 Delphi7 中则移至 Variants 单元。文章还讨论了在设置表格字段值时遇到的问题,即直接赋值整数或浮点数值导致错误,而通过 StrToInt 或 StrToFloat 函数转换后再赋值则能正常工作。
1243

被折叠的 条评论
为什么被折叠?



