diff --git a/include/filetext.cpp b/include/filetext.cpp index c535bf369..a6292a85a 100755 --- a/include/filetext.cpp +++ b/include/filetext.cpp @@ -143,8 +143,11 @@ TTracciato_campo& TTracciato_record::get(int n) } //////////////////////////////////////// TRecord_text //////////////////////////////////////// const TString& TRecord_text::row(int pos) const -{ - return _array.row(pos); +{ + const TString* str = (const TString*)_array.objptr(pos); + if (str != NULL) + return *str; + return EMPTY_STRING; } TString& TRecord_text::row(int pos) @@ -573,15 +576,19 @@ int TFile_text::write(TRecord_text& rec) const TString& type = rec.type(); TTracciato_record& tr = *t_rec(type); + const int items = rec.items(); if (_typepos>=0) rec.add(type,_typepos); + + const TArray& tac = tr.tracciati_campo(); + if (_fixedlen) // campi a lunghezza fissa { - for (int i = 0; i < items; i++) + FOR_EACH_ARRAY_ITEM(tac, i, obj) { - TTracciato_campo& tc = tr.get(i); - campo = rec.row(i); + const TTracciato_campo& tc = tr.get(i); + campo = rec.get(i); format_textfield(tc, campo); buffer.overwrite(campo, tc.position()); } @@ -606,10 +613,11 @@ int TFile_text::write(TRecord_text& rec) else { buffer.separator(_fieldsep); - for (int i = 0; i < items; i++) + FOR_EACH_ARRAY_ITEM(tac, i, obj) { - TTracciato_campo& tc = tr.get(i); - campo = format_textfield(tc, rec.row(i)); + const TTracciato_campo& tc = tr.get(i); + campo = rec.get(i); + format_textfield(tc, campo); buffer.add(campo); } CHECK(_write_file, "Impossibile scrivere su un file chiuso.");