Experience in developing database programs with Delphi

Source: Internet
Author: User
Tags interbase
1. Create a temporary table
Data input is an inevitable step for developing database programs. In the Client/Server structure, the client may need to input a batch of data before submitting the data to the backend database of the server. This requires local (client) create a temporary data table to store user input data. After the data is submitted, clear the local table data. The advantage of this method is that it increases the input efficiency and reduces the network burden.

Because the data size you input at a time is usually small (no more than several hundred records), the temporary table can be created in the memory, so the processing speed is faster.
Method 1: Use the query control (tquery)
Step 2: Put the query control (tquery) on the form and set the connected data table.
Step 1: Make tquery. cachedupdates = true;
Tquery. requestlive = true
Step 2: Add a where substatement after the original SQL statement. The SQL query result is blank after the where substatement is added.
For example:
Select biolife. "species no", category, common_name, biolife. "species name", biolife. "length (CM)", length_in, notes, graphic
From "biolife. DB" biolife
Where biolife. Category = 'A 'and biolife. Category =' B ′
In this way, the temporary table is created.

Method 2: Use code to create a temporary table
The Code is as follows:
Function createtableinmemory (const afielddefs: tfielddefs): tdataset;
VaR
Temptable: tclientdataset;
Begin
Temptable: = nil;
Result: = nil;
If afielddefs <> nil then
Begin
Try
Temptable: = tclientdataset. Create (application );
Temptable. fielddefs. Assign (afielddefs );
Temptable. createdataset;
Result: = (temptable as tdataset );
Except
If temptable <> nil then
Temptable. Free;

Result: = nil;
Raise;
End
End
End;

Use the following method in the program:
Procedure tform1.button1click (Sender: tobject );
VaR
Adataset: tdataset;
Begin
Adataset: = tdataset. Create (Self );
With adataset. fielddefs do
Begin
Add ('name', ftstring, 30, false );
Add ('value', ftinteger, 0, false );
End;

With performance1 do
Begin
Dataset: = createtableinmemory (adataset. fielddefs );
Dataset. open;
End;

Adataset. Free;
End;

Temporary table created.

Method 1 is easy to use. However, because the query control is used to clear data, the server background database needs to be queried, so the speed is a little slow, it is not applicable to the scenario where fields in the temporary table are pieced together by fields in several data tables. Method 2 is widely used and fast, but code needs to be written. (The use of tfielddefs in the code is very simple. See the online help of Delphi ).

2. Configure the Data Engine (BDE, SQL link)
When distributing database programs, the Data Engine (BDE and SQL link) needs to be carried, and the data engine needs to be configured after the client installs the program, such as username and password) and so on. If manually configured, the workload is relatively large (depending on the number of clients ). InstallShield for Delphi does not seem to have this option. In fact, InstallShield for Delphi can do this. There is a * in the directory where the installation program is generated *. for iwz text files, you only need to manually add them to the [idapi alias] segment. For example:
[Idapi alias]
Usesname = sysdba
Password = masterkey
After the program is installed, the Data Engine is automatically configured.

3. Use functions in the Interbase Database
When using INTERBASE as the background database, programmers may feel inconvenient to provide too few functions (only four) for them, and cannot easily compile complex stored procedures. Interbase itself cannot write functions, but it can use external functions (call functions in DLL ). The following example describes how to declare the substr function in InterBase.
Declare external function substr
Cstring (80), smallint, smallint
Returns cstring (80)
Entry_point "ib_udf_substr" module_name "ib_udf ″

Module_name indicates the DLL name and entry_point indicates the function name.
You can use it after declaration, for example:
Select substr (country)
From country

This example uses the iblocal database that comes with Delphi during installation. You can also write functions to expand InterBase.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.