I have a form with the following controls: TDBEdit, TDBMemo, TDataSource, TClientDataSet

If the user edits the fields and then clicks a button on the form that simply calls the MyCDS.Cancel method (to cancel the edits), the TDBEdit fields revert to their original values, but the TDBMemo fields are not reverted (they are set to blank values).

The TClientDataSet is populated from a MSSQLServer 2008 database. The TDBEdit fields are nvarchar(255) in the database, and the TDBMemo are nvarchar(max) or xml fields.

Looking at the values in the Debug Inspector (ctrl+F7, MyCDS.FieldByName('afield'), Inspect) shows the following for one of the nvarchar(max) fields:

  • DataSize = 0
  • DataType = ftWideMemo
  • Size = 1

This is the same for all of the nvarchar(max) and xml fields whether or not the underlying field has data or not.

It appears that there is an incompatibility between the nvarchar(max) (which is treated as a ftWideMemo) and the TDBMemo control.

Has anyone seen issues like this before? Do you have any suggestions how to resolve it?

有帮助吗?

解决方案

In case anyone in interested, the problem is a bug in the TClientDataSet component. The problem only occurs when you clone a dataset, don't have a Provider and turn LogChanges off. If you edit a record on the cloned dataset and then cancel the edit, then any memo fields lose their values.

Since you don't necessarily use a Provider in file-based applications, it doesn't always make sense to enable LogChanges. However, to work around the limitation with memo fields, you can leave LogChanges on, and then call MergeChangeLog after operations that change the cloned dataset.

I created a program that demonstrates the issue. See the Embarcadero incident QC#110511.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top