Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to access DBF database in Delphi

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

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

The xBase database stores a large amount of formatted data in a structured form in a .dbf data file. In a database like dBase, the .dbf file stores a table that retains the table description, field descriptor, and record. Modern databases like dBase also have files for large text fields (memos), commands, procedures, backups, and so on.

There are a variety of database engines that can read and manipulate data in DBF files, but none of them understand all formats of xBase databases-- most of these database engines can interact with one or two dialects of the xBase series. Unlike other existing solutions, the Delphi data access provider TDBFUniProvider in UniDAC provides an engine that understands DBF files in many dBase-like databases.

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

TDBFUniProvider provides direct access to the xBase database and supports all dBase native data types (characters, numbers, logic, data, memos). It is used as a SQL engine to execute commands on database files. The Delphi code in the project is compiled into an executable file, and no other external files are needed to access and manipulate the data in the DBF file.

The UniDAC Delphi component for accessing xBase database files supports multiple database file formats: dBase III, dBase IV, dBase V, dBase VII, FoxPro2, Visual FoxPro, Clipper, CodeBase, HiPer-Six. In addition to allowing developers to use standard SQL-92 syntax, it also provides a quick way to rebuild tables and delete deleted records to reduce the size of database files.

Create a sample Delphi application to access the xBase database

We will create a simple Delphi application that connects to the database in Visual FoxPro format and displays the records in the table when the Show button is clicked.

1. Find the TUniConnection, TUniQuery, TUniDataSource, TDBFUniProvider, TDBGrid, and TButton components in the tool palette and place them on the form.

Double-click the UniConnection1 component on the form. Switch to the options tab and set Direct to True.

3. Return to the connection tab, select DBF as the provider, and enter the path to Visual FoxPro (or any other xBase database) on your computer. Click Connect. If all goes well, the red circle will turn green.

4. In UniDataSource1, set the DataSet property to UniQuery1.

Select DBGrid1 and set the DataSource property to UniDataSource1.

6. Select the UniQuery1 component and set the Connection property to UniConnection1, then double-click the component and enter the SQL statement. Click OK.

7. Change the title property of the button to display in the object inspector. Double-click the button, switch to the Code tab and add UniQuery1.Open; to the OnClick event handler code.

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

Retrieve corrupted data and metadata

XBase dialects have a long history, and it is not uncommon for fields in .dbf files to contain data of unsupported types. To solve any problem with unsupported data types, UniDAC provides two options: IgnoreDataErrors and IgnoreMetaDataErrors. The former option forces UniDAC to ignore corrupted data errors when opening the DBF table, while the latter option causes UniDAC to ignore metadata errors: when both options are set to True, corrupt data is skipped and other data is retrieved correctly.

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

Supported target platform

UniDAC supports multiple target platforms: you can create an application that accesses the 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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report