First, the introduction
C + + Buidler and Dephi are examples of rad, making it possible to develop programs quickly, efficiently, and easily. However, in the process of using C + + Buidler, it is found that not only familiar with C + + Buidler VCL components can successfully complete the program writing, but also need to pay attention to some easily overlooked details. This article lists some problems encountered, and provides solutions for reference.
Ii. Specific problems and solutions
1. When using SQL statements to manipulate a database, if a variable appears in the statement, the same variable cannot be reused
For example: To access the data table T1 and T2 in accordance with the conditions t1.t1_f1= "01" and T2.t2_f1= "01" records, according to conventional thinking, simply set a variable p in the SQL statement, respectively, to determine whether the T1.T1_F1 and t2.t2_f1 value is "01", The BCB statement is as follows:
if(ADOQuery1->Active)
{ ADOQuery1->Close();
ADOQuery1->SQL->Clear(); }
ADOQuery1->SQL- >Text="SELECT * FROM T1, T2 WHERE T1.T1_F1=:p AND T2.T2_F1=:p";
ADOQuery1->Parameters->ParamValues ["p"]="01";
ADOQuery1->Open();
However, after this code is run, the result of the query is empty. (confirmed during the access Access2003) by tracing the variable p in the SQL statement, the second call to P is found, the BCB does not assign a value to P, that is, p is null, so the expected query result is not obtained. The correct parameter settings should be:
ADOQuery1->SQL- >Text="SELECT * FROM T1, T2 WHERE T1.T1_F1=:p1 AND T2.T2_F1=:p2";
ADOQuery1->Parameters->ParamValues ["p1"]="01";
ADOQuery1->Parameters- >ParamValues["p2"]="01";
As you can see from the above, BCB uses only once for each assignment variable that appears in the SQL statement. Even if you need to assign the same value to a variable that appears two times in an SQL statement, apply two variables and assign the values separately.
2. Use of goto statements
In the goto statement for C + + Builder, if the reserved word goto has an initialization statement with a local variable between the target identity:
goto EndMark;// EndMark为目标标识
int a=1;
……
EndMark:;
An error occurs when running the goto statement, which is inconvenient for the use of a goto statement, but can run smoothly if a pair of curly brackets is added between Goto and the target identity:
goto EndMark;
{ int a=1;
…… }
EndMark:;
C + + Builder will {...} The initialization of the variable in the local variable is understood to be initialization, and the initialization of the local variable does not affect the statement outside the {}. Therefore, you can eliminate the restriction that C + + Builder uses for GOTO statements by appropriately using curly braces.