Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi and Firedac : query Active vs query Open

Tags:

delphi

firedac

Most of my application's forms use 2 or more db grids : basically, the user clicks a record in main grid and get child results in a secondary grid.

All my primary DBGrids FDQueries (that is the one with SELECT) have been set on the form but none are "active", they fire on FormShow.

I noticed that, wether I write :

FDQuery1.Active := True;

or

FDQuery1.Open;

the result is the same : my rows are displayed in the main DBGrid.

Accordingly, I call Close or Active := False on FormClose.

But there must be a difference between those approaches and this is the subject of my question : what is the difference between Query.Open and Query.Active := True; ?

What should I use if there is any significant difference ?

Thanks in advance

Math, getting less and less noob as you take the time to answer my questions :)

SIDE NOTE : my INSERT and UPDATE queries are set up with a CLEAR then, SQL.ADD, then Parameters declaration and finally an ExecSQL

like image 399
Mathmathou Avatar asked Nov 24 '25 11:11

Mathmathou


2 Answers

Active is a property, Open is a method. When Active is set to true, it calls the Open method, when it is set to false, it calls Close. Active is useful as it can be used to check whether the dataset is actually open.

if Qry.Active then DoSomething;
like image 111
RED MONKEY Avatar answered Nov 27 '25 09:11

RED MONKEY


SIDE NOTE : my INSERT and UPDATE queries are set up with a CLEAR then, SQL.ADD, then Parameters declaration and finally an ExecSQL

Between Active and Open is no difference.(see whosrdaddy comment) They do the same thing - The dataset becomes active and returns the result from SELECT statement.

You can also use property Active to check if the dataset is active for example:

if not MyQuery.Active then 
  MyQuery.Open; // or MyQuery.Active := true;

ExecSQL execute queries that do not return a cursor to data (such as INSERT, UPDATE, DELETE, and CREATE TABLE).

like image 31
Val Marinov Avatar answered Nov 27 '25 08:11

Val Marinov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!