Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

What is the best way to do this in Delphi?

Posted on 2011-10-20
3
Medium Priority
?
222 Views
Last Modified: 2012-08-13
I need to create a adoquery in execution time.

what is the best way to create, with application or nil in create?

var
  TQ : Tadoquery;
begin
  TQ := Tadoquery.create(Application)

  OR

  TQ := Tadoquery.create(Nil)
end;



End to destoy it?

TQ.Close;
FreeAndNil(TQ)

Or

TQ.free


Thanks
0
Comment
Question by:hidrau
  • 2
3 Comments
 
LVL 25

Accepted Solution

by:
epasquier earned 2000 total points
ID: 36999216
Usually you create components with a FORM owner. The Owner MUST be a TComponent, which is the case of TApplication.
The component (ADOQuery) will be destroyed automatically when the owner is destroyed.
If you set no Owner (nil), then you will HAVE to destroy it manually.

But there is no best way to create dynamically the component, it depends on how much control on your object life you need/want,how much public is that ADO object (used by only one form or two ? or always available in all your forms and units ?) and where you create/destroy your object.

Then, that said, the best is to not create dynamically those objects, but put one at design time in a data module. Let Delphi manage automatically the datamodule and its owned components (the ADOQuery will be one of them).
0
 
LVL 1

Author Comment

by:hidrau
ID: 36999364
ok, I understood - thanks
0
 
LVL 1

Author Closing Comment

by:hidrau
ID: 36999367
thanks
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month15 days, 15 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question