Bugfix of TFixedLengthExporter component
Original Reporter info from Mantis: zgabrovski
-
Reporter name: Zdravko Gabrovski
Original Reporter info from Mantis: zgabrovski
- Reporter name: Zdravko Gabrovski
Description:
It seems, that TFixedLengthExporter component had never been designed to work properly with UTF-8 international character set text.
I found also, that the component has no functionality to export a dataset field names.
Another bug that I catch was, that it does a wrong left alignment on floating point fields, instead of expected right alignment.
And finally, when the property "DateFormat" and "DateTimeFormat" in Format settings are assigned, it displays NULL value fields as wrongly formatted zero date (31.12.1899) instead of empty field.
So the fixes are:
Creating a new TCustomFixedLengthExporter.InternalExportField(EF: TExportFieldItem;ExportCaption:Boolean); - to work with UTF8 functions, instead of wrong non-utf8 (Copy to Utf8copy, Delete To utf8delete, Length to UTF8Legth).
The new procedure was copied from TCustomFixedLengthExporter.ExportField, because I decide to re-use the same for display of DataHeader row.
Flag ExportCaption:Boolean will indicate if the procedure will return a data row (when it is called from TCustomFixedLengthExporter.ExportField or Header row, if it is called from DoDataHeader).
Here is the code of the new procedure:
procedure TCustomFixedLengthExporter.InternalExportField(EF: TExportFieldItem;ExportCaption : Boolean );
Var
S,SS : String;
W,L : Integer;
FL : TFixedLengthExportFieldItem;
begin
if ExportCaption then
S := Ef.ExportedName
else
S:=FormatField(EF.Field);
If EF is TFixedLengthExportFieldItem then
begin
FL:=TFixedLengthExportFieldItem(EF);
W:=FL.Width;
end
else
W:=UTF8Length(S);
L:=UTF8Length(S);
If L>W then
begin
If (FL.AlignField=afLeft) then
S:=UTF8Copy(S,1,W)
else
UTF8Delete(S,1,L-W);
end
else if (L<W) then
begin
SS:=StringOfChar(' ',W-L);
If FL.AlignField=afRight then
S:=SS+S
else
S:=S+SS;
end;
if FCurrentRow <> '' then
S := ' ' + S;
FCurrentRow:=FCurrentRow+S;
end;
Other changes in fpdbexport.pp:
- Add a new constant FloatFieldTypes = [ftFloat, ftCurrency, ftFMTBcd, ftBCD];
this will be used into TFixedLengthExporter to fix a problem with wrong field alignment into procedure
procedure TCustomFixedLengthExporter.BuildDefaultFieldMap(AMap: TExportFields);
The change is:
If (F.DataType in IntFieldTypes) or ( F.DataType in FloatFieldTypes) then
Fl.AlignField:=afRight;
- Fix the procedure for field formatting to avoid a problem with wrong date and timestamp fields formatting.
If (FormatSettings.DateFormat<>'') and ( not F.IsNull ) then <-----------------------------------------
Result:=FormatDateTime(FormatSettings.DateFormat,F.AsDateTime)
else if FormatSettings.UseDisplayText then
Result:=F.DisplayText
else
Result:=F.AsUTF8String;
end
else if (F.DataType=ftTime) then
begin
If (FormatSettings.TimeFormat<>'') and ( not F.IsNull ) then <-----------------------------------------
Result:=FormatDateTime(FormatSettings.TimeFormat,F.AsDateTime)
else if FormatSettings.UseDisplayText then
Result:=F.DisplayText
else
Result:=F.AsUTF8String;
end
else if (F.DataType in [ftDateTime,ftTimeStamp]) then
begin
If (FormatSettings.DateTimeFormat<>'') and ( not F.IsNull ) then <-----------------------------------------
Result:=FormatDateTime(FormatSettings.DateTimeFormat,F.AsDateTime)
Now it seems to work OK. Please, find attached files.
Steps to reproduce:
As described.
Mantis conversion info:
- Mantis ID: 36304
- OS: all
- OS Build: all
- Build: trunk
- Platform: all
- Version: 3.3.1
- Fixed in version: 3.3.1
- Fixed in revision: 46743558.
- Target version: 3.2.0