[fpc-devel] TFieldDef.Size vs TField.Size

LacaK lacak at zoznam.sk
Thu Feb 24 08:02:20 CET 2011

I am writting here to discuss bug 
(I do not want reopen bug and writte there because I am not sure about 
my arguments)

IMHO root of problem is in different definition of TFieldDef.Size and 
Documentation says, that
1. TFieldDef.Size should be "For string and byte fields, *Size* is the 
number of bytes reserved "
2. TField.Size should be "the maximum number of characters in the 
string" (for ftString and I guess that also for ftWideString)

And now let's go look into fields.inc:
1. Function TFieldDef.CreateField copies Result.Size:=FSize (so 
2. function TStringField.GetDataSize returns for ftString ... Size+1
3. function TWideStringField.GetDataSize returns for ftWideString ... 
(Size + 1) * 2

Points 2,3 are clear Size is expected to be number of characters, 
DataSize number of bytes.
But point 1 says, that TFieldDef.Size and TField.Size should be the same

And now let's go look into bufdataset.pas:
4. function TCustomBufDataset.GetFieldSize works with TFieldDef and 
returns number of bytes needed in record buffer
  case FieldDef.DataType of
    ftString, ftGuid, ftFixedChar: result := FieldDef.Size + 1;
    ftFixedWideChar, ftWideString:result := (FieldDef.Size + 1)*2;
So also here we can see, that FieldDef.Size is expected to be number of 
characters not bytes.

So IMHO logical conclusion will be say, that TFieldDef.Size for string 
fields has same menaing as Field.Size, so it is number of characters
(so documentation is wrong in this case ... also fast test in Delphi 
shows, that FieldDef.Size=Field.Size=number of characters)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20110224/1ac409b6/attachment.html>

More information about the fpc-devel mailing list