Author | Topic: Re: Dbf Data Conversion | |
---|---|---|
Andreas Gehrs-Pahl View the complete thread for this message in: | Re: Dbf Data Conversion on Thu, 08 Dec 2016 14:58:36 -0500 Carlos, Depending on what you actually need, there are several ways to accomplish what you want. 1) You could leave the databases as they are (DBF format with standard OEM characters), and have your application use Set(_SET_CHARSET, CHARSET_OEM) before reading or writing any data from/to those databases if you use an ANSI default setting in your application. This will prevent any implicit character conversions. You can do that even more specifically only before accessing any fields that contain I2Bin() data, while letting the other fields be (implicitly) converted. 1a) If that is too cumbersome, and you don't want to switch the Character Set all the time, but leave your application in ANSI mode, you could use DbeInfo(COMPONENT_DATA, DBFDBE_ANSI, .t.) before opening the database. This will also prevent any implicit character conversions. If you then need to explicitly convert the data from a particular field, you can use the ConvToAnsiCP() function. 2) You can also convert the databases permanently to FOX format, using the OEM character set (and Code Page 437), while converting the fields with I2Bin() data to binary fields (using the "X" field type with DbStruct()). This will create a database with a modified (FOX) header, but the data is otherwise exactly the same as in the original (DBF format) file. The only thing you need to change in your demo program to accomplish this, is to remove (or remark out) line 54, which contains: Set(_SET_CHARSET, CHARSET_ANSI). 2a) You can also convert the databases permanently to FOX format, using the ANSI character set (and Code Page 1252), while converting the fields with I2Bin() data to binary fields (using the "X" field type with DbStruct()). This will create a database with a modified (FOX) header, and the character fields (that were not changed to binary) will have been converted to ANSI. The only thing you need to change in your demo program to accomplish this, is to (leave line 54 as it is, but) add somewhere between line 62 (after the DbCreate()) and line 81 (before the loop in which you write data to the new database) the following line: Set(_SET_CHARSET, CHARSET_OEM). There are actually some additional options, but I guess you can figure those out by yourself. Just keep in mind that the implicit and explicit character conversion between OEM and ANSI is not always reversible, so you probably should try and limit those conversions as much as possible and only convert characters when absolutely necessary. Also, please keep in mind that characters displayed by an XbpCRT() object will always be in the OEM charset, while characters displayed by an XbpSLE() object will always be in the ANSI charset. Depending on your active CharSet setting, implicit conversions might be performed, before something is displayed in one or the other. Hope that helps, Andreas Andreas Gehrs-Pahl Absolute Software, LLC phone: (989) 723-9927 email: Andreas@AbsoluteSoftwareLLC.com web: http://www.AbsoluteSoftwareLLC.com [F]: https://www.facebook.com/AbsoluteSoftwareLLC |