#1 2013-07-17 12:21:07

esmondb
Member
From: London
Registered: 2010-07-20
Posts: 299

TSQLTable.FieldLengthMax and Enumerate type fields

Could FieldLengthMax be changed so that with sftEnumerate it gives the max caption length, like below?

function TSQLTable.FieldLengthMax(Field: integer; NeverReturnsZero: boolean): cardinal;
var i: integer;
    len: cardinal;
    U: PPUTF8Char;
begin
  result := 0;
  if (self<>nil) and (cardinal(Field)<cardinal(FieldCount)) then begin
    if not Assigned(fFieldType) then
       InitFieldTypes;
    if fFieldType[Field].ContentType = sftEnumerate then begin
      for i := 0 to PEnumType(fFieldType[Field].EnumTypeInfo)^.MaxValue do begin
        len := length(PEnumType(fFieldType[Field].EnumTypeInfo)^.GetCaption(i));
        if len > result then
          result := len;
      end;
    end else begin
      U := @fResults[FieldCount+Field]; // start reading after first Row
      for i := 1 to RowCount do begin
        len := StrLen(U^);
        if len>result then
          result := len;
        inc(U,FieldCount);
      end;
    end;
  end;
  if (result=0) and NeverReturnsZero then
    result := 1; // minimal not null length
end;

Offline

Board footer

Powered by FluxBB