has anyone had problems with the use of the pascal version of the file 'ShapefileII.pas'? The OSGEO maintain a DLL to manage shapefile and DBF associated file (https://github.com/OSGeo/shapelib).
I'm trying to create a shp file and the associated .DBF file using Delphi-10.3-Rio. I can create the SHP and DBF file, but I can not add/updade string field data to the DBF file.
I used the steps described in the example file 'dbfadd.c' using the function 'DBFWriteStringAttribute' and 'DBFWriteIntegerAttribute'.
The function does not return any errors, but the string field in DBF file is not updated.
I know that is related to differences PChar C++ and PAnsichar in Delphi 10.3 code.
The Delphi equivalent from C++ is:
function DBFWriteIntegerAttribute(hDBF: DBFHandle; iShape: LongInt; iField: LongInt; nFieldValue: LongInt): LongInt; cdecl;
function DBFWriteStringAttribute(hDBF: DBFHandle; iShape: LongInt; iField: LongInt; pszFieldValue: PAnsiChar{PChar}): LongInt; cdecl;
//c++ DLL code
{ function DBFWriteIntegerAttribute(hDBF: DBFHandle;iShape: LongInt; iField: LongInt; nFieldValue: LongInt): LongInt; cdecl;
DBFWriteStringAttribute( DBFHandle hDBF, int iShape, int iField, const char * pszFieldValue ); int}
Please, can anyone help me? Here my code:
//open dbf file and add/update data
FDBFHandle := DBFOpen(pAnsichar(FileNameDBF), pAnsichar('r+b')); //open a DBF file created
if FDBFHandle = nil then exit;
iRecord:= DBFGetRecordCount(FDBFHandle); // get record number
DBFWriteIntegerAttribute(FDBFHandle, iRecord, 0, 99 ); //works fine update first field
DBFWriteStringAttribute (FDBFHandle, iRecord, 1, PAnsichar('TEST' ));//NOT WORK BUT RETURN TRUE AND SAVE VALUE '0' TO FIELD
//Using PAnsistring also not work
DBFClose(FDBFHandle);