@@ -718,6 +718,9 @@ bool CTableClass::SaveToFile(const CStringW& dbfFilename, bool updateFileInPlace
718718 return false ;
719719 }
720720
721+ // is the Shapefile UTF-8 (if unspecified or specified as UTF-8)
722+ bool isUTF8 = (DBFGetCodePage (_dbfHandle) == nullptr || strcmp (DBFGetCodePage (_dbfHandle), " UTF-8" ) == 0 );
723+
721724 // joined fields must be removed; they will be restored in the process of reopening table
722725 // after saving operation
723726 this ->RemoveJoinedFields ();
@@ -799,7 +802,7 @@ bool CTableClass::SaveToFile(const CStringW& dbfFilename, bool updateFileInPlace
799802 continue ;
800803 }
801804
802- if (!WriteRecord (newdbfHandle, rowIndex, ++currentRowIndex))
805+ if (!WriteRecord (newdbfHandle, rowIndex, ++currentRowIndex, isUTF8 ))
803806 {
804807 ErrorMessage (tkDBF_CANT_WRITE_ROW);
805808 return false ;
@@ -935,6 +938,8 @@ void CTableClass::LoadDefaultFields()
935938 field->put_Width (fwidth);
936939 field->put_Precision (fdecimals);
937940 field->put_Type ((FieldType)type);
941+ // // field has not really been modified
942+ // ((CField*)field)->SetIsUpdated(false);
938943
939944 FieldWrapper* fw = new FieldWrapper ();
940945 fw->oldIndex = i;
@@ -1440,7 +1445,7 @@ bool CTableClass::ReadRecord(long RowIndex)
14401445// WriteRecord()
14411446// *******************************************************************
14421447// Write a cached RecordWrapper into dbf file
1443- bool CTableClass::WriteRecord (DBFInfo* dbfHandle, long fromRowIndex, long toRowIndex)
1448+ bool CTableClass::WriteRecord (DBFInfo* dbfHandle, long fromRowIndex, long toRowIndex, bool isUTF8 )
14441449{
14451450 AFX_MANAGE_STATE (AfxGetStaticModuleState ())
14461451 USES_CONVERSION ;
@@ -1454,7 +1459,7 @@ bool CTableClass::WriteRecord(DBFInfo* dbfHandle, long fromRowIndex, long toRowI
14541459 if (fromRowIndex < 0 || fromRowIndex >= RowCount ())
14551460 return false ;
14561461
1457- char * nonstackString = NULL ;
1462+ const char * nonstackString = NULL ;
14581463
14591464 for (long i = 0 ; i < FieldCount (); i++)
14601465 {
@@ -1468,7 +1473,7 @@ bool CTableClass::WriteRecord(DBFInfo* dbfHandle, long fromRowIndex, long toRowI
14681473 {
14691474 if (val.vt == VT_BSTR )
14701475 {
1471- nonstackString = Utility::SYS2A (val.bstrVal );
1476+ nonstackString = Utility::ConvertBSTRToLPSTR (val. bstrVal , (isUTF8 ? CP_UTF8 : CP_ACP )); // ((LPCSTR)Utility::ConvertToUtf8(val.bstrVal)); // Utility:: SYS2A(val.bstrVal);
14721477 DBFWriteStringAttribute (dbfHandle, toRowIndex, i, nonstackString);
14731478 delete[] nonstackString;
14741479 nonstackString = NULL ;
0 commit comments