Mark,
If I am using the same query several times in the same procedure in quick
succession I will leave the SQL the same and simply change the parameters
each time I want to run it. I don't know about speed in recreating a query
time after time - I haven't done any benchmark tests, but I don't think I
work with enough large datasets to make a difference.
It doesn't take a noticeable time period to create a query that I can see.
Since I have started using this method I haven't seen any drop in
performance at all. The only thing I have to do is remember to qryTemp.Free
at the end of each procedure as the TQuery is not linked to a form, and
therefore if you don't destroy it the memory would never be freed.
I haven't had enough experience with Delphi to have investigated things like
'Preparing' queries. I read the help file and it says things go quicker if
you explicitely prepare a query but I can't see it.
One of the major reasons I use this method is that I can make reuseable code
for different applications in units without any forms, so I don't have to
have a form to link the query to. Saves me having to remember to put a
TQuery on the main form called qrySetup for example.
Steve
-----Original Message-----
From: Mark Howard [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, 20 June 2001 10:04
To: Multiple recipients of list delphi
Subject: Re: [DUG]: Use of TQuery's
Steve
Do you still do this if you have a query that you may wish to call several
times?
If you prepare the query once, then opening it subsequently should be
much(?) faster than re-creating it each time.
Mark
----- Original Message -----
From: "Steve Aish" <[EMAIL PROTECTED]>
To: "Multiple recipients of list delphi" <[EMAIL PROTECTED]>
Sent: Wednesday, June 20, 2001 9:55 AM
Subject: RE: [DUG]: Use of TQuery's
> I have taken to creating queries on the fly instead of having a whole lot
of
> Utility queries sitting on my screens.
>
> e.g.
>
> procedure DoSomething();
> var
> qryTemp : TQuery;
> begin
> qryTemp := TQuery.Create(nil);
> qryTemp.DatabaseName := strDatabaseName; // where strDatabaseName is a
> global variable naming the alias
>
> qryTemp.SQL.Add('SELECT .... ');
> qryTemp.Open;
>
> ...
>
> qryTemp.Free;
> end;
>
> Is this good or bad programming programming practice. You don't have to
> worry about whether you are using a query that should be still open for
some
> other purpose.
>
> Steve
>
>
>
> -----Original Message-----
> From: Mark Derricutt [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, 20 June 2001 09:43
> To: Multiple recipients of list delphi
> Subject: RE: [DUG]: Use of TQuery's
>
>
> Coincidentally I thought about this last night and am working out a layout
> for a simple TDataSetPool component, that I can set to have a maximum
> number of datasets, and then just call something like GetDataset, and
it'll
> return an unused one from the pool.
>
> I've often had a TQuery sitting around that I use for generic on the fly
> queries instead of creating/freeing one in the local procedure, but
> occasionally get into the case when one event that uses the same TQuery
> gets called at the same time as another, and causes problems...
>
> Mark
>
> --On Tuesday, June 19, 2001 2:28 PM +1200 James Low <[EMAIL PROTECTED]>
> wrote:
>
> > 3) I have one Utility query which I create odds and sodds queries, such
> > as for establishing if records exist/ dont exist etc.
>
>
>
>
> --------------------------------------------------------------------------
-
> New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
> Website: http://www.delphi.org.nz
> To UnSub, send email to: [EMAIL PROTECTED]
> with body of "unsubscribe delphi"
> --------------------------------------------------------------------------
-
> New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
> Website: http://www.delphi.org.nz
> To UnSub, send email to: [EMAIL PROTECTED]
> with body of "unsubscribe delphi"
>
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED]
with body of "unsubscribe delphi"
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED]
with body of "unsubscribe delphi"