How to access DBF databases in Delphi

xBase is a general term for all derived from the original database format dBase (.dbf) database. The list includes Visual FoxPro, Clipper, dBase III, dBase IV and so on. These databases are informally known as dBase clones because they are direct descendants of dBase or imitators.

xBase large database .dbf format data stored in a data file in a structured form. In a similar dBase database, a table .dbf file storage, which retains the table description, and a recording field descriptor. Similar modern dBase database also has a file for large text fields (memo), commands, procedures, and other backup.

There are a variety of database engines can read and manipulate data in DBF file, but they do not understand all formats xBase database - most of these are in the xBase database engine series or two dialects interact. Unlike other existing solutions, Delphi data access provider in UniDAC TDBFUniProvider provides an engine that can understand many similar dBase DBF files in the database.

UniDAC is a universal database access component that provides direct access to multiple databases, such as for Windows Delphi, C ++ Builder, Lazarus (and Free Pascal), Mac OS X, iOS, Android, Linux , and 64 and 32 the FreeBSD and so on.

TDBFUniProvider xBase provide direct access to the database and supports all dBase native data type (character, number, logic, data, memo). It is used as the SQL engine, execute commands on the database file. Project Delphi code is compiled into an executable file, you do not need any other external files to access and manipulate data DBF file.

UniDAC Delphi components for accessing xBase database files support a variety of database file formats: dBase III, dBase IV, dBase V, dBase VII, FoxPro2, Visual FoxPro, Clipper, CodeBase, HiPer-Six. In addition to SQL-92 syntax allows developers to use standard, it also provides a quick way to rebuild the table and remove deleted records, to reduce the size of the database file.

Create a sample Delphi applications to access xBase database

We will create a simple Delphi application, the application will connect to the Visual FoxPro database format, and click "Show" records in the table display button.

1, find TUniConnection, TUniQuery, TUniDataSource, TDBFUniProvider, TDBGrid and TButton component in the "tool palette" in and place them on the form.

UniDAC Tutorial: How to access DBF databases in Delphi

2, double-click on the form UniConnection1 assembly. Switch to the "Options" tab, then "direct" is set to True.

UniDAC Tutorial: How to access DBF databases in Delphi

3, return to the "Connections" tab, select "DBF" As a provider, and then enter the computer Visual FoxPro (or any other xBase database) path. Click Connect. If all goes well, the red circle will turn green.

UniDAC Tutorial: How to access DBF databases in Delphi

4, in UniDataSource1, the DataSet property to UniQuery1.

UniDAC Tutorial: How to access DBF databases in Delphi

5, and selecting DBGrid1 DataSource property to UniDataSource1.

UniDAC Tutorial: How to access DBF databases in Delphi

6, component selection and UniQuery1 Connection property to UniConnection1, and then double-click the component and enter SQL statements. Click OK.

UniDAC Tutorial: How to access DBF databases in Delphi

7, the button "title" attribute change "is displayed in the object inspector." Double-click the button to switch to the "Code" tab and add UniQuery1.Open; to the OnClick event handler code.

55dbf_delphi_onclick2.png

8. Press F9 to compile and run your application. If the program compiles without errors, you should see the application form has been compiled. Click Show to acquire and view the data in Visual FoxPro table.

UniDAC Tutorial: How to access DBF databases in Delphi

Retrieve corrupted data and metadata

xBase dialect has a long history, .dbf file field contains unsupported type of data is not uncommon. To resolve any unsupported data types of questions, UniDAC offers two options: IgnoreDataErrors and IgnoreMetaDataErrors . Before a mandatory option when you open the DBF table UniDAC ignore corrupted data error, then an option to ignore the UniDAC metadata error: When both options are set to True, will skip the damaged data, and other data retrieved properly.

Another feature is that when you do not fully understand the DBF file format ( DBFFormat options dfAuto value), can automatically determine the dialect xBase database.

Supported target platforms

UniDAC support multiple target platforms: You can create an application to access a DBF database for:

  • Windows, 32-bit and 64-bit

  • macOS, 32-bit and 64-bit

  • iOS, 32-bit and 64-bit

  • Android, 32-bit and 64-bit

  • Linux, 32-bit and 64-bit


Guess you like

Origin blog.51cto.com/14467432/2451924