Delphi Development Experience

zhaozj2021-02-08  236

Author: Gao Su-mei

Simple method for configuring data engines (BDE, SQL LINK)

When the database program is distributed, you need to carry the data engine (BDE, SQL LINK), and configure the data engine after the client is installed, such as username, password (password), and more. If you are manually configured, the workload is relatively large. At this time, we can use InstallShield for Delphi to easily implement configuration. When making an installer with InstallShield for Delphi, there is a * .iwz text file in the directory where the installer is generated, as long as it is manually added in the [Idapi Alias] clip. E.g:

[IDAPI Alias]

Username = sysdba

Password = MasterKey

The data engine is automatically configured after the installer.

Method for making fast button bars

Each graphic button on the fast button bar represents a common function, while these graphic buttons are more common than ordinary icons, they can place larger, more image graphics, can even bring short tips, which User's most commonly used features is very helpful. Based on the above reasons, more and more Windows applications use a fast button strip to improve the interface interface. When the author is programmed with Delphi, two different methods are used to implement the fast button bar. This article combines an instance of the fast button bar with two groups, a total of six buttons, listing the specific design steps of these two methods. .

Group generation method

(1) Place a panel1 object on the form, as a carrier of the graphic button.

(2) Set the attribute attribute of Panel1, which is empty, attribute Align is Altop, adjust its height to the appropriate size.

(3) Place six SpeedButton buttons on Panel1 (select SpeedButton because it has floating characteristics).

(4) Place two Bevel objects on Panel1, adjust its location and size, and used to separate the button group.

(5) Adjust the size of SpeedButton1 and the position in Panel1.

(6) Select SpeedButton1 to set its property FLAT to TRUE.

(7) Click the omitted number of the miniPH corresponding to the attribute glyph of SpeedButton1, open the PictureEeditor window, select a symbolizing icon. Setting attribute showhint to true, property hint is "query".

(8) The properties of the remaining SPEEDBUTTON buttons are set separately according to the methods of steps (5) to (7).

In this way, a quick button bar is completed. When running, the quick button is displayed in a floating mode. When the mouse is moved to it, the display button is displayed, and a small prompt is displayed.

2. Borrow Toolbar generation method

(1) Place a TOOLBAR1 object on the form.

(2) Set the properties of Toolbar1 EDGEBORDERS.EBLEFT, EBTOP, EBRIGHT, EBBUTTOM all; attribute Flat is true; adjust the size of Toolbar1 to the appropriate size.

(3) Select Toolbar1, use the right-click quick order, and click NewButton and NewseParator to add six button Toolbutton and two separate column lines.

(4) Any option to select a Toolbutton button to adjust its size to a suitable size, all ToolButton is also adjusted at the same time.

(5) Set the properties of Toolbar1 BorderWidth to 3 to adjust the location of Toolbutton.

(6) Place an ImageList1 object on the form, set its properties height, and width, to accommodate larger images.

(7) Double-click ImageList1, and load six images via the "Add", and correspond to the six Toolbutton in Toolbar1. (8) Set the properties of Toolbar1 images to imagelist1.

(9) Set six ToolButton's properties showHint to true and set the respective small prompt properties Hint.

(10) You can also set the picture set when Toolbar1's HotImages specifies the image point when the mouse pointing to the button.

The quick button bar implemented by Toolbar is similar to the first method.

The above two methods can achieve the quick button bar, but each has a thousand autumn: the first design process is simpler; the second method provides more features, such as using hotimages to specify the image set when the mouse pointing to the button. The reader may wish to choose one and continue to improve its function.

Establish a temporary table

Data input is an inevitable link to the development of the database program. In the Client / Server structure, the client may be submitted to the server's background database, which requires the local (client) to establish a temporary data table to store data input data, after submit, clear Local data sheet. The advantage of this method is to improve input efficiency and reduce network burden.

Since the data amount of the user is in a general case (no more than hundreds of records), the temporary table can be built in memory so that the processing speed is faster. Temporary table creation has the following two methods:

1. Create a temporary table using the query control

Step 1: Place the query control (TQuery) on the form and set the connected data sheet.

Step 2: Add the following statement:

TQuery. Cachedupdates = TRUE;

TQuery. RequestLive = true.

Step 3: Add a WHERE child statement after the original SQL statement, requiring the result of the SQL query after adding this WHERE child statement.

E.g:

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'

This temporary table is established.

2. Create a temporary table using the code

The function code is as follows:

Function CreateTableInMemory (const Afielddefs: tfielddefs):

TDataSet;

Var Temptable: TclientDataSet;

Begin

Temptable: = NIL;

Result: = NIL;

IF Afielddefs <> nil dam

Begin

Try

Temptable: = TclientDataSet.create (Application);

Temptable.fielddefs.assign (AfieldDefs);

Temptable.created;

Result: = (Temptable as TdataSet);

Except

IF Temptable <> nil damptable.free;

Result: = NIL;

Raise;

end

end

END;

Call as follows:

Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);

Var adataset: tdatanet;

Begin

Adataset: = tdataset.create (self); with adataset.fielddefs do

Begin

Add ('Name', FTString, 30, False);

Add ('Value', Ftinteger, 0, False);

END;

With datasource1 do

Begin

DataSet: = CreateTableInMemory; Adataset.fieldDefs;

DataSet.open;

END;

Adataset.free;

END;

In this way, the temporary table is created.

Method 1 is simple, but since the query control is used to empty the data, you need to query the server backbench database, so the speed is slightly slow, and it is not applicable to the field of several data tables in the temporary table. Method 2 has a wide range of applications, fast, but needs to write code.

Use functions in the InterBase database

When the programmer may use InterBase as a background database, it is often used to provide an inconvenience for the function provided (only four), and the complex stored procedure cannot be easily written. Interbase itself cannot write a function, but it can use an external function (call the function in the DLL). The following example shows 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"

Where: Module_name is the name of the DLL, entry_point is the function name.

You can use it after the declaration, for example:

SELECT SUBSTR (Country)

From country

This example uses the IBLocal database that comes with Delphi installation, and users can write a function to expand Interbase.

转载请注明原文地址:https://www.9cbs.com/read-2377.html

New Post(0)