|
@@ -29,9 +29,13 @@ Type
|
|
TFixedExportFormatSettings = Class (TExportFormatSettings)
|
|
TFixedExportFormatSettings = Class (TExportFormatSettings)
|
|
private
|
|
private
|
|
FCharMode: TCharMode;
|
|
FCharMode: TCharMode;
|
|
|
|
+ FHeaderRow: Boolean;
|
|
Public
|
|
Public
|
|
Procedure Assign(Source: TPersistent); override;
|
|
Procedure Assign(Source: TPersistent); override;
|
|
Published
|
|
Published
|
|
|
|
+ // Whether or not the file should have a header row with field names
|
|
|
|
+ Property HeaderRow : Boolean Read FHeaderRow Write FHeaderRow default true;
|
|
|
|
+ // How to handle Unicode ?
|
|
Property CharMode : TCharMode Read FCharMode Write FCharMode;
|
|
Property CharMode : TCharMode Read FCharMode Write FCharMode;
|
|
end;
|
|
end;
|
|
|
|
|
|
@@ -41,12 +45,12 @@ Type
|
|
FCurrentRowUnicode : UnicodeString;
|
|
FCurrentRowUnicode : UnicodeString;
|
|
function GetCharMode: TCharMode;
|
|
function GetCharMode: TCharMode;
|
|
function GeTFixedExportFormatSettings: TFixedExportFormatSettings;
|
|
function GeTFixedExportFormatSettings: TFixedExportFormatSettings;
|
|
- procedure SeTFixedExportFormatSettings(AValue: TFixedExportFormatSettings);
|
|
|
|
|
|
+ procedure SetFixedExportFormatSettings(AValue: TFixedExportFormatSettings);
|
|
Protected
|
|
Protected
|
|
- function ExportFieldAsUniCodeString(EF: TExportFieldItem): UnicodeString; virtual;
|
|
|
|
- procedure ExportFieldAnsi(EF: TExportFieldItem); virtual;
|
|
|
|
- procedure ExportFieldUTF16(EF: TExportFieldItem); virtual;
|
|
|
|
- procedure ExportFieldUTF8(EF: TExportFieldItem); virtual;
|
|
|
|
|
|
+ function ExportFieldAsUniCodeString(EF: TExportFieldItem; isHeader: Boolean=False): UnicodeString; virtual;
|
|
|
|
+ procedure ExportFieldAnsi(EF: TExportFieldItem; isHeader: Boolean=False); virtual;
|
|
|
|
+ procedure ExportFieldUTF16(EF: TExportFieldItem; isHeader: Boolean=False); virtual;
|
|
|
|
+ procedure ExportFieldUTF8(EF: TExportFieldItem; isHeader: Boolean=False); virtual;
|
|
Procedure BuildDefaultFieldMap(AMap : TExportFields); override;
|
|
Procedure BuildDefaultFieldMap(AMap : TExportFields); override;
|
|
Function CreateExportFields : TExportFields; override;
|
|
Function CreateExportFields : TExportFields; override;
|
|
Function CreateFormatSettings: TCustomExportFormatSettings; override;
|
|
Function CreateFormatSettings: TCustomExportFormatSettings; override;
|
|
@@ -55,13 +59,12 @@ Type
|
|
Procedure DoDataRowStart; override;
|
|
Procedure DoDataRowStart; override;
|
|
Procedure ExportField(EF : TExportFieldItem); override;
|
|
Procedure ExportField(EF : TExportFieldItem); override;
|
|
Procedure DoDataRowEnd; override;
|
|
Procedure DoDataRowEnd; override;
|
|
|
|
+ Procedure DoDataHeader; override;
|
|
Property CharMode : TCharMode Read GetCharMode;
|
|
Property CharMode : TCharMode Read GetCharMode;
|
|
- Property FixedFormatSettings : TFixedExportFormatSettings Read GeTFixedExportFormatSettings Write SeTFixedExportFormatSettings;
|
|
|
|
|
|
+ Property FormatSettings : TFixedExportFormatSettings Read GetFixedExportFormatSettings Write SetFixedExportFormatSettings;
|
|
end;
|
|
end;
|
|
|
|
|
|
TFixedLengthExporter = Class(TCustomFixedLengthExporter)
|
|
TFixedLengthExporter = Class(TCustomFixedLengthExporter)
|
|
- Public
|
|
|
|
- Property FixedFormatSettings;
|
|
|
|
Published
|
|
Published
|
|
Property FileName;
|
|
Property FileName;
|
|
Property Dataset;
|
|
Property Dataset;
|
|
@@ -93,7 +96,10 @@ uses math;
|
|
procedure TFixedExportFormatSettings.Assign(Source: TPersistent);
|
|
procedure TFixedExportFormatSettings.Assign(Source: TPersistent);
|
|
begin
|
|
begin
|
|
if (Source is TFixedExportFormatSettings) then
|
|
if (Source is TFixedExportFormatSettings) then
|
|
|
|
+ begin
|
|
CharMode:=TFixedExportFormatSettings(Source).CharMode;
|
|
CharMode:=TFixedExportFormatSettings(Source).CharMode;
|
|
|
|
+ HeaderRow:=TFixedExportFormatSettings(Source).HeaderRow;
|
|
|
|
+ end;
|
|
inherited Assign(Source);
|
|
inherited Assign(Source);
|
|
end;
|
|
end;
|
|
|
|
|
|
@@ -117,19 +123,19 @@ end;
|
|
{ TCustomFixedLengthExporter }
|
|
{ TCustomFixedLengthExporter }
|
|
|
|
|
|
|
|
|
|
-procedure TCustomFixedLengthExporter.SeTFixedExportFormatSettings(AValue: TFixedExportFormatSettings);
|
|
|
|
|
|
+procedure TCustomFixedLengthExporter.SetFixedExportFormatSettings(AValue: TFixedExportFormatSettings);
|
|
begin
|
|
begin
|
|
- FormatSettings:=AValue;
|
|
|
|
|
|
+ Inherited FormatSettings:=AValue;
|
|
end;
|
|
end;
|
|
|
|
|
|
function TCustomFixedLengthExporter.GetCharMode: TCharMode;
|
|
function TCustomFixedLengthExporter.GetCharMode: TCharMode;
|
|
begin
|
|
begin
|
|
- Result:=FixedFormatSettings.CharMode;
|
|
|
|
|
|
+ Result:=FormatSettings.CharMode;
|
|
end;
|
|
end;
|
|
|
|
|
|
function TCustomFixedLengthExporter.GeTFixedExportFormatSettings: TFixedExportFormatSettings;
|
|
function TCustomFixedLengthExporter.GeTFixedExportFormatSettings: TFixedExportFormatSettings;
|
|
begin
|
|
begin
|
|
- Result:=Formatsettings as TFixedExportFormatSettings;
|
|
|
|
|
|
+ Result:=(Inherited Formatsettings) as TFixedExportFormatSettings;
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure TCustomFixedLengthExporter.BuildDefaultFieldMap(AMap: TExportFields);
|
|
procedure TCustomFixedLengthExporter.BuildDefaultFieldMap(AMap: TExportFields);
|
|
@@ -190,12 +196,12 @@ Const
|
|
Case charmode of
|
|
Case charmode of
|
|
cmUTF8:
|
|
cmUTF8:
|
|
begin
|
|
begin
|
|
- LTrue:=Length(UTF8Decode(FixedFormatSettings.BooleanTrue));
|
|
|
|
- LFalse:=Length(UTF8Decode(FixedFormatSettings.BooleanFalse));
|
|
|
|
|
|
+ LTrue:=Length(UTF8Decode(FormatSettings.BooleanTrue));
|
|
|
|
+ LFalse:=Length(UTF8Decode(FormatSettings.BooleanFalse));
|
|
end;
|
|
end;
|
|
else
|
|
else
|
|
- LTrue:=Length(FixedFormatSettings.BooleanTrue);
|
|
|
|
- LFalse:=Length(FixedFormatSettings.BooleanFalse);
|
|
|
|
|
|
+ LTrue:=Length(FormatSettings.BooleanTrue);
|
|
|
|
+ LFalse:=Length(FormatSettings.BooleanFalse);
|
|
end;
|
|
end;
|
|
Result:=Max(LTrue,LFalse);
|
|
Result:=Max(LTrue,LFalse);
|
|
end;
|
|
end;
|
|
@@ -271,7 +277,7 @@ begin
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
-Function TCustomFixedLengthExporter.ExportFieldAsUniCodeString(EF: TExportFieldItem) : UnicodeString;
|
|
|
|
|
|
+Function TCustomFixedLengthExporter.ExportFieldAsUniCodeString(EF: TExportFieldItem; isHeader : Boolean = False) : UnicodeString;
|
|
|
|
|
|
Var
|
|
Var
|
|
S,SS : UnicodeString;
|
|
S,SS : UnicodeString;
|
|
@@ -279,7 +285,10 @@ Var
|
|
L,W : Integer;
|
|
L,W : Integer;
|
|
|
|
|
|
begin
|
|
begin
|
|
- S:=UTF8Decode(FormatField(EF.Field));
|
|
|
|
|
|
+ if isHeader then
|
|
|
|
+ S:=UTF8Decode(EF.ExportedName)
|
|
|
|
+ else
|
|
|
|
+ S:=UTF8Decode(FormatField(EF.Field));
|
|
If EF is TFixedLengthExportFieldItem then
|
|
If EF is TFixedLengthExportFieldItem then
|
|
begin
|
|
begin
|
|
FL:=TFixedLengthExportFieldItem(EF);
|
|
FL:=TFixedLengthExportFieldItem(EF);
|
|
@@ -306,21 +315,21 @@ begin
|
|
Result:=S;
|
|
Result:=S;
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TCustomFixedLengthExporter.ExportFieldUTF16(EF: TExportFieldItem);
|
|
|
|
|
|
+procedure TCustomFixedLengthExporter.ExportFieldUTF16(EF: TExportFieldItem; isHeader : Boolean = False);
|
|
|
|
|
|
begin
|
|
begin
|
|
- FCurrentRowUnicode:=FCurrentRowUnicode+ExportFieldAsUnicodeString(EF);
|
|
|
|
|
|
+ FCurrentRowUnicode:=FCurrentRowUnicode+ExportFieldAsUnicodeString(EF,isHeader);
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
-procedure TCustomFixedLengthExporter.ExportFieldUTF8(EF: TExportFieldItem);
|
|
|
|
|
|
+procedure TCustomFixedLengthExporter.ExportFieldUTF8(EF: TExportFieldItem; isHeader : Boolean = False);
|
|
|
|
|
|
|
|
|
|
begin
|
|
begin
|
|
- FCurrentRow:=FCurrentRow+UTF8Encode(ExportFieldAsUnicodeString(EF));
|
|
|
|
|
|
+ FCurrentRow:=FCurrentRow+UTF8Encode(ExportFieldAsUnicodeString(EF,isHeader));
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TCustomFixedLengthExporter.ExportFieldAnsi(EF: TExportFieldItem);
|
|
|
|
|
|
+procedure TCustomFixedLengthExporter.ExportFieldAnsi(EF: TExportFieldItem; isHeader : Boolean = False);
|
|
|
|
|
|
Var
|
|
Var
|
|
S,SS : String;
|
|
S,SS : String;
|
|
@@ -328,7 +337,10 @@ Var
|
|
FL : TFixedLengthExportFieldItem;
|
|
FL : TFixedLengthExportFieldItem;
|
|
|
|
|
|
begin
|
|
begin
|
|
- S:=FormatField(EF.Field);
|
|
|
|
|
|
+ if isHeader then
|
|
|
|
+ S:=EF.ExportedName
|
|
|
|
+ else
|
|
|
|
+ S:=FormatField(EF.Field);
|
|
If EF is TFixedLengthExportFieldItem then
|
|
If EF is TFixedLengthExportFieldItem then
|
|
begin
|
|
begin
|
|
FL:=TFixedLengthExportFieldItem(EF);
|
|
FL:=TFixedLengthExportFieldItem(EF);
|
|
@@ -365,6 +377,31 @@ begin
|
|
FCurrentRowUnicode:='';
|
|
FCurrentRowUnicode:='';
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+procedure TCustomFixedLengthExporter.DoDataHeader;
|
|
|
|
+
|
|
|
|
+Var
|
|
|
|
+ I : Integer;
|
|
|
|
+ EF: TExportFieldItem;
|
|
|
|
+
|
|
|
|
+begin
|
|
|
|
+ FCurrentRow:='';
|
|
|
|
+ if FormatSettings.HeaderRow then
|
|
|
|
+ begin
|
|
|
|
+ For I:=0 to ExportFields.Count-1 do
|
|
|
|
+ begin
|
|
|
|
+ EF:=ExportFields[I];
|
|
|
|
+ If EF.Enabled then
|
|
|
|
+ Case CharMode of
|
|
|
|
+ cmANSI : ExportFieldAnsi(EF,True);
|
|
|
|
+ cmUTF8 : ExportFieldUTF8(EF,True);
|
|
|
|
+ cmUTF16 : ExportFieldUTF16(EF,True);
|
|
|
|
+ end;
|
|
|
|
+ end;
|
|
|
|
+ DoDataRowEnd;
|
|
|
|
+ end;
|
|
|
|
+ inherited DoDataHeader;
|
|
|
|
+end;
|
|
|
|
+
|
|
Procedure RegisterFixedExportFormat;
|
|
Procedure RegisterFixedExportFormat;
|
|
|
|
|
|
begin
|
|
begin
|