2

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?

James L.
  • 9,384
  • 5
  • 38
  • 77
  • 2
    What is the field type the `TDBMemo` is connected to? Also, two thoughts: 1) Why aren't you simply using `SysUtils.Abort;`, since the exception is supposed to be silent? and 2) Wouldn't it just be easier to disable the ability to navigate away once editing has begun until they've either saved or cancelled the edit? – Ken White Nov 14 '12 at 23:14
  • @Ken - I revised the question. it now reflects my latest troubleshooting. – James L. Nov 15 '12 at 00:31
  • Nicely revised. (+1, BTW - should have done that before.) I don't have SQL Server 2008 on this machine, so I won't be able to try and reproduce the issue until tomorrow; I'm afraid I don't have any suggestions at this point. There are several people that frequent Delphi questions here that are pretty knowledgeable about `TClientDataSet`, so you'll probably get an answer pretty quickly. If not, I'll look into it first thing tomorrow if I can. – Ken White Nov 15 '12 at 00:41
  • I'm going to work on a standalone simple app to try and reproduce it as well. The current bug shows up in my client app that pulls data through a DataSnap server. So there are several more variables involved. I need eliminate those that aren't a factor... – James L. Nov 15 '12 at 02:02

1 Answers1

0

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.

James L.
  • 9,384
  • 5
  • 38
  • 77