No possibility to specify dbf codepage in dbfexporter
It is no possible to specify the code page of the dbf file generated by the dbf exporter.
System Information
- Operating system: Windows
- Processor architecture: x86-64
- Compiler version: FPC 3.3.1 i386-win32-win32/win64
- Device: Computer
Steps to reproduce
- Load the demo project in the folder components/dbexport/demo/simple showing application of various dbexporters, among them the dbf exporter.
- Modify the procedure
OpenDataset()
to display the codepage of the loaded dbf file:
procedure TMainForm.OpenDataset(AFileName : String);
begin
...
Caption:=Format('%s (%s) codepage %d',[FDesignCaption,AFileName,DBFData.Codepage]);
end;
- Compile and run the project. Load the sample data file
testdata.dbf
provided with the sample code. The form's caption shows that the test file has codepage 1252. - Click the toolbutton to export to dbf format.
- After the export load the created dbf file into the application. Now the form's caption shows that the test file has code page 850.
- Maybe the mentioned codepages are valid for my (German) system only, but the steps show that there is no way to control the codepage of the generated dbf file.
Example Project
- Use the project in components/dbexport/demo/simple coming with the Lazarus installation. (see above).
What is the current bug behavior?
- The user cannot control the codepage of the generated dbf file.
What is the expected (correct) behavior?
- The user should be able to specify the codepage of the generated dbf file.
Possible fixes
See attached patch. It introduces a new property LanguageID to the TDBFExportFormatSettings. LanguageID is used rather than codepage itself because it is the easiest way to define the codepage of a not-yet existing dbf file, and because it also contains locale information (alternatively, two properties, CodePage and Locale, could be added separately and combined by the ConstructLangID()
function in ``dbf_lang.pas'' to get the LanguageID. When the destination dbf file is created the LanguageID is transferred from the TDBFExportFormatSettings to the dbf file.
Or maybe a more general solution should be attempted in which code page support is added to all exporter types (I am aware that this might make my current patch obsolete).
There should also be a possibility to perform the code page conversion on the fly during the export process; an event OnTranslate
in the export settings, similar to TDataset.OnTranslate
comes to my mind.