What is the best way to do this in Delphi?

Posted on 2011-10-20
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?

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


  TQ := Tadoquery.create(Nil)

End to destoy it?



Question by:hidrau
    LVL 25

    Accepted Solution

    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).
    LVL 1

    Author Comment

    ok, I understood - thanks
    LVL 1

    Author Closing Comment


    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    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…
    Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

    746 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now