Author: Gao Sumei
Simple way to configure data engines (BDE, SQL Link)
When the database program is distributed, the data engine (BDE, SQL Link) needs to be carried, and after the program is installed on the client, the data engine needs to be configured, such as username (username), password (PassWord), etc. If manual configuration is required, the workload will be relatively large. At this time, we can use InstallShield For Delphi to easily implement the configuration. When using InstallShield For Delphi to create an installation program, there is a *.iwz text file in the directory where the installation program is generated. You only need to manually add it to the [IDAPI Alias] fragment. For example:
[IDAPI Alias]
username=SYSDBA
password=masterkey
After installing the program, the data engine is automatically configured.
How to make a quick button strip
Each graphic button on the quick button bar represents a commonly used function. At the same time, these graphic buttons are larger in size than ordinary icons. Larger and more vivid graphics can be placed, and they can even carry short prompts, which is very useful for It's helpful for users to perform the most commonly used functions. Based on the above reasons, more and more Windows applications adopt quick button strips to improve the application interface. When programming in Delphi, the author uses two different methods to implement a quick button bar. This article combines an example of making a quick button bar with two groups of six buttons and lists the specific design steps of these two methods. .
1. Combination generation method
(1) Place a Panel1 object on the form as the carrier of the graphic button.
(2) Set the Caption attribute of Panel1 to empty, the Align attribute to alTop, and adjust its height to the appropriate size.
(3) Place six SpeedButton buttons on Panel1 (SpeedButton is selected because it has floating characteristics).
(4) Place two Bevel objects on Panel1 and adjust their position and size to separate the button groups.
(5) Adjust the size and position of SpeedButton1 in Panel1.
(6) Select SpeedButton1 and set its property Flat to True.
(7) Click the small ellipsis button corresponding to the attribute Glyph of SpeedButton1, open the PictureEditor window, and select an icon symbolizing "query". Set the property ShowHint to True and the property Hint to "Query".
(8) Follow steps (5) to (7) to set the properties of the remaining SpeedButton buttons.
In this way, a quick button strip is completed. When running, the quick buttons are displayed in a floating manner. When the mouse is moved over them, the button outline is displayed and a small prompt is displayed.
2. Borrow the ToolBar generation method
(1) Place a ToolBar1 object on the form.
(2) Set the properties EdgeBorders.ebLeft, ebTop, ebRight, and ebButtom of ToolBar1 to True; the property Flat to True; adjust the size of ToolBar1 to the appropriate size.
(3) Select ToolBar1, right-click the quick menu, click NewButton and NewSeparator respectively to add six ToolButton buttons and two separator lines.
(4) Select any ToolButton button and adjust its size to the appropriate size. All ToolButtons will also be adjusted at the same time.
(5) Set the property BorderWidth of ToolBar1 to 3 to adjust the position of ToolButton.
(6) Place an ImageList1 object on the form and set the values of its properties Height and Width to accommodate larger-sized images.
(7) Double-click ImageList1 and load six images respectively through the "Add" button, corresponding to the six ToolButtons in ToolBar1.
(8) Set the property Images of ToolBar1 to ImageList1.
(9) Set the ShowHint attribute of the six ToolButtons to True, and set their respective small prompt attributes Hint.
(10) You can also set the HotImages of ToolBar1 to specify the picture set when the mouse points to the button.
The quick button bar implemented using ToolBar is similar in appearance to the one made by the first method.
Both of the above methods can implement a quick button bar, but each has its own merits: the first design process is relatively simple; the second method provides more functions, such as using HotImages to specify the picture set when the mouse points to the button. Readers may wish to choose one and continue to improve its functions.
How to create a temporary table
Data entry is an inevitable part of developing database programs. In the Client/Server structure, the client may input a batch of data and then submit it to the server's backend database. This requires a temporary data table to be established locally (client) to store the data entered by the user. After submission, it will be cleared. Local data table. The benefits of this method are: improving input efficiency and reducing network burden.
Since the amount of data input by users at one time is generally small (no more than a few hundred records), the temporary table can be established in memory, which results in faster processing. There are two ways to create a temporary table:
1. Use query control to create a temporary table
Step 1: Place the query control (TQuery) on the form and set up the connected data table.
Step 2: Add the following statement:
TQuery.CachedUpdates=True;
TQuery.RequestLive=True.
Step 3: Add a Where sub-statement after the original SQL statement. It is required that the SQL query result will be empty after adding this Where sub-statement.
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.
2. Use code to create a temporary table
The function 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;
Call it in the program as follows:
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 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 to use, but due to the use of query control, the server background database needs to be queried when clearing data, so the speed is slightly slower, and it is not suitable for situations where each field in the temporary table is composed of fields from several data tables. Method 2 has a wide range of applications and is fast, but requires writing code.
Using functions in InterBase database
When programmers use InterBase as a backend database, they often find it inconvenient to use because it provides too few functions (only four), making it impossible to easily write complex stored procedures. InterBase itself cannot write functions, but it can use external functions (call functions 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"
Among them: MODULE_NAME is the name of the DLL, and ENTRY_POINT is the function name.
It can be used after declaration, for example:
select SUBSTR(country)
from country
This example uses the IBLocal database that comes with Delphi installation. Users can also write their own functions to expand InterBase.