2929#include " Field.h"
3030#include " TableHelper.h"
3131#include " FieldHelper.h"
32+ #include " Shapefile.h"
3233
3334#pragma warning(disable:4996)
3435
@@ -717,6 +718,9 @@ bool CTableClass::SaveToFile(const CStringW& dbfFilename, bool updateFileInPlace
717718 return false ;
718719 }
719720
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+
720724 // joined fields must be removed; they will be restored in the process of reopening table
721725 // after saving operation
722726 this ->RemoveJoinedFields ();
@@ -798,7 +802,7 @@ bool CTableClass::SaveToFile(const CStringW& dbfFilename, bool updateFileInPlace
798802 continue ;
799803 }
800804
801- if (!WriteRecord (newdbfHandle, rowIndex, ++currentRowIndex))
805+ if (!WriteRecord (newdbfHandle, rowIndex, ++currentRowIndex, isUTF8 ))
802806 {
803807 ErrorMessage (tkDBF_CANT_WRITE_ROW);
804808 return false ;
@@ -934,6 +938,8 @@ void CTableClass::LoadDefaultFields()
934938 field->put_Width (fwidth);
935939 field->put_Precision (fdecimals);
936940 field->put_Type ((FieldType)type);
941+ // // field has not really been modified
942+ // ((CField*)field)->SetIsUpdated(false);
937943
938944 FieldWrapper* fw = new FieldWrapper ();
939945 fw->oldIndex = i;
@@ -1439,7 +1445,7 @@ bool CTableClass::ReadRecord(long RowIndex)
14391445// WriteRecord()
14401446// *******************************************************************
14411447// Write a cached RecordWrapper into dbf file
1442- bool CTableClass::WriteRecord (DBFInfo* dbfHandle, long fromRowIndex, long toRowIndex)
1448+ bool CTableClass::WriteRecord (DBFInfo* dbfHandle, long fromRowIndex, long toRowIndex, bool isUTF8 )
14431449{
14441450 AFX_MANAGE_STATE (AfxGetStaticModuleState ())
14451451 USES_CONVERSION;
@@ -1453,7 +1459,7 @@ bool CTableClass::WriteRecord(DBFInfo* dbfHandle, long fromRowIndex, long toRowI
14531459 if (fromRowIndex < 0 || fromRowIndex >= RowCount ())
14541460 return false ;
14551461
1456- char * nonstackString = NULL ;
1462+ const char * nonstackString = NULL ;
14571463
14581464 for (long i = 0 ; i < FieldCount (); i++)
14591465 {
@@ -1467,7 +1473,7 @@ bool CTableClass::WriteRecord(DBFInfo* dbfHandle, long fromRowIndex, long toRowI
14671473 {
14681474 if (val.vt == VT_BSTR)
14691475 {
1470- 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);
14711477 DBFWriteStringAttribute (dbfHandle, toRowIndex, i, nonstackString);
14721478 delete[] nonstackString;
14731479 nonstackString = NULL ;
@@ -1991,6 +1997,8 @@ STDMETHODIMP CTableClass::EditDeleteRow(long RowIndex, VARIANT_BOOL *retval)
19911997 AFX_MANAGE_STATE (AfxGetStaticModuleState ())
19921998 *retval = VARIANT_FALSE;
19931999
2000+ ((CShapefile*) _shapefile)->MarkShapeDeleted (RowIndex);
2001+
19942002 if (_isEditingTable == FALSE )
19952003 {
19962004 ErrorMessage (tkDBF_NOT_IN_EDIT_MODE);
0 commit comments