后台使用SQL语句中,经常会关联自定义函数或视图,而CDS(TClientDataSet)对字段校验比较严格,涉及到的自定义函数或视图输出的字段,都会强制改为ReadOnly为True属性。
当后台使用UniDAC+CDS,关联视图或自定义函数,为了数据一致性,有可能需要在前台界面上修改CDS相关的自定义函数输出的字段,即便是将 该字段设置为 readonly为false,或将其字段的 FieldDefs属性的attributes的faReadOnly去掉,系统也会抛出一个异常:trying to modify read-only Field。

解决问题很简单,将TUniQuery.Options.SetFieldsReadOnly为false即可。
查一下TUniQuery.Options.SetFieldsReadOnly的帮助,这样写道:
If True, dataset sets the ReadOnly property to True for all fields that do not belong to UpdatingTable or can not be updated. Set this option for datasets that use automatic generation of the update SQL statements only.
解决CDS字段只读问题
本文介绍在使用UniDAC+CDS时遇到的字段只读问题及其解决方案。当需要修改由自定义函数或视图输出的字段时,系统可能会抛出异常。文章提供了解决方法,只需将TUniQuery.Options.SetFieldsReadOnly设为false即可。
3558

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



