How to use TQuery misleading in the manual

zhaozj2021-02-08  226

Q: How to use TQuery misleading in the manual

A: When developing a database with a Delphi, you will often use the TQuery, there are many examples on it in the manual, and the general structure is as follows:

Query1.close; query1.parambyname ('id'). Asstring: = '001'; query1.open; string: = query1.fieldbyname ('id'). Asstring;

Many users will encounter slow speed, more resource consumption, and even exact resources when developing. This is why, in fact, there are some pieces of the manual, misleading everyone.

Delphi has an important feature that is DB Aware, connecting DBGRID with Query, Query's result set will be automatically displayed in DBGRID. In order to ensure that DBGRID is always displayed, query needs to always keep Active. When modifying Query's query conditions, turn off Query first, and modify the query condition and open it. This is the meaning of the above code.

The problem is that when Query does not connect to the DB Aware component, how should you write a code if you have other tables in a calculated field event. At this time, you don't need to keep Query to active. In contrast, in order to reduce unnecessary waste, you should keep deActive. So the code should be as follows:

Query1.Parambyname ('ID'). Asstring: = '001'; query1.open; string: = query1.fieldbyname ('id'). Asstring; query1.close;

When you use query, you should pay attention to select the appropriate method according to the actual situation, do not be misleaded by the manual.

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

New Post(0)