On Thu, 24 Feb 2011, LacaK wrote:

Hi,
I am writting here to discuss bug http://bugs.freepascal.org/view.php?id=17268 (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 TField.Size
Documentation says, that
1. TFieldDef.Size should be "For string and byte fields, *Size* is the number of bytes reserved "
  http://docwiki.embarcadero.com/VCL/en/DB.TFieldDef.Size
2. TField.Size should be "the maximum number of characters in the string" (for ftString and I guess that also for ftWideString)
  http://docwiki.embarcadero.com/VCL/en/DB.TField.Size
  http://docwiki.embarcadero.com/VCL/en/DB.TStringField.Size

And now let's go look into fields.inc:
1. Function TFieldDef.CreateField copies Result.Size:=FSize (so TField.Size:=TFieldDef.Size)
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

Correct, if you assume 1 char = 1 byte.

(so documentation is wrong in this case ... also fast test in Delphi shows, that FieldDef.Size=Field.Size=number of characters)

Your story is confusing to me. Where do you see a problem ?

Do you see an implementation problem or a documentation problem ?

Note that nowhere in the documentation pages you mention, widestrings are
mentioned (which is convenient, since that's where 1 char <> 1 byte).

Michael.
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply via email to