Jump to content
Navid Madani

TClientDataSet's odd behavior with hyphens in string fields

Recommended Posts

In the DUnitX tests below, the first 4 cases fail: the last character is omitted. It seems that for each hyphen added after the first, an extra character from the end is not written to the TClientDataSet field. 

 

Is this normal behavior? Thanks in advance.

 

unit uCDSTest;

interface

uses
    DUnitX.TestFramework
  , Data.DB
  , Datasnap.DBClient
  ;

type
  [TestFixture]
  TClientDataSetTest = class
  private
    fCDS: TClientDataSet;
  public
    [Setup]
    procedure Setup;
    [TearDown]
    procedure TearDown;
    [Test]
    [TestCase('Test0','S0002-9270(99)00035-0')]
    [TestCase('Test1','S0002-9270(99)00035-1')]
    [TestCase('Test2','S0002-9270(99)00035-2')]
    [TestCase('Test3','S0002-9270(99)00035-3')]
    [TestCase('Test4','S0002-9270(99)000353')]
    [TestCase('Test5','S00029270(99)00035-3')]
    [TestCase('Test6','S00-02-9270(99)00035-3')]
    [TestCase('Test7','S00-02-92-70(99)00035-3')]
    procedure TestCDS(const AValue : string);
  end;

implementation

const
  cFieldname = 'AFieldName';

procedure TClientDataSetTest.Setup;
var
  fd: TFieldDef;
begin
  fCDS := TClientDataSet.Create(nil);
  fd := fCDS.FieldDefs.AddFieldDef;
  fd.Name := cFieldname;
  fd.DataType := ftString;
  fCDS.CreateDataSet;
end;

procedure TClientDataSetTest.TearDown;
begin
  fCDS.Free;
end;

procedure TClientDataSetTest.TestCDS(const AValue : string);
begin
  fCDS.Insert;
  fCDS.Edit;
  fCDS.FieldByName(cFieldname).AsString := AValue;
  fCDS.Post;
  Assert.AreEqual(AValue, fCDS.FieldByName(cFieldname).AsString, 'Assignment failed.');
end;

initialization
  TDUnitX.RegisterTestFixture(TClientDataSetTest);

end.

 

Edited by Navid Madani
Minor edits

Share this post


Link to post
1 hour ago, Dmitry Arefiev said:

fd.Size := 50;

Thank Dmitry, but I did not grasp the implication of your terse comment. The size of string fields needs to be set?

Share this post


Link to post
4 minutes ago, Navid Madani said:

The size of string fields needs to be set?

ftString size is default to 20. If you want not to set the size then you can use ftMemo.

Share this post


Link to post
15 minutes ago, Cristian Peța said:

ftString size is default to 20. If you want not to set the size then you can use ftMemo.

Duh! Thank you! I should have tested adding other characters on the tests.  When the REST API added the hyphens, that's when everything broke down ...

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×