'Delphi BatchMoveTextReader with Umlauts
I have the following problem: I have this .CSV file, let's say we have headers like this:
id;demo;ä;ö;ü
1;text;umlauts1;umlauts2;umlauts3
.
.
.
When I use FormatGuessing to load this file at design time, everything works as expected; 5 fields in TFDBatchmoveTextReader are generated.
When I run the guessing at runtime, headers with umlatus like ä,ö,ü,ß are not in the fieldlist.
I tried using different encodings for the textreader to use. Does not matter. The file is ANSI. I also tried to convert the file to UTF8 and use UTF8 as encoding. Nothing changes.
Any ideas how I can get the headers with special characters in them?
My code for running the batchmove looks like that:
TextReader.FileName := str;
FDLocalSQL1.Active := false;
if Memtable.State in [dsEdit, dsInsert] then
begin
Memtable.ClearFields;
Memtable.FieldDefs.Clear;
end;
Memtable.Active := false;
QueryToMemtable.Active := false;
Memtable.LocalSQL := FDLocalSQL1;
QueryToMemtable.LocalSQL := FDLocalSQL1;
QueryToMemtable.FetchOptions.RecordCountMode := cmTotal;
TextReader.DataDef.Fields.Clear;
BatchMove.Mappings.Clear;
TextReader.DataDef.Delimiter := '"';
TextReader.DataDef.Separator := ';';
TextReader.DataDef.RecordFormat := rfCustom;
TextReader.DataDef.WithFieldNames := True;
TextReader.DataDef.FormatSettings.DecimalSeparator := '.';
TextReader.DataDef.FormatSettings.DateSeparator := '-';
TextReader.DataDef.FormatSettings.ShortDateFormat := 'yyyy/MM/dd';
TextReader.DataDef.FormatSettings.ShortTimeFormat := 'HH:mm:ss';
TextReader.Encoding := ecANSI;
BatchMove.AnalyzeSample := 100000;
BatchMove.GuessFormat;
Debug('File containing the following fields');
for var I := 0 to TextReader.DataDef.Fields.Count - 1 do
begin
Debug(TextReader.DataDef.Fields.Items[I].FieldName);
end;
BatchMove.Execute;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
