Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8462577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:12:10+00:00 2026-06-10T14:12:10+00:00

I have one fundamental doubt in Delphi. When I keep any component at design

  • 0

I have one fundamental doubt in Delphi. When I keep any component at design time, say for example TADOConnectuion and on button click even I write following code then I do not get any error:

begin
  ADOConnection.Free;  //No error
  ADOConnection.Free;  //No error
  ADOConnection.Free;  //No error
end;

But if I create the same object at run time as follwos I get “Access Violation…” error

begin
  ADOConnection := TADOConnection.create(self);
  ADOConnection.Free;  //No error
  ADOConnection.Free;  //Getting an "Access Violation..." error
end;

I get the same error even though I create the object as below:

ADOConnection := TADOConnection.create(nil);

Just would like to know the reason behind such behaviour, i.e. why there is no error when I keep the component at design time ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T14:12:11+00:00Added an answer on June 10, 2026 at 2:12 pm

    If you free a component, its corresponding field in the owner is cleared. If you add a design-time ADOConnection, then

    ADOConnection.Free; // Frees ADOConnection and sets ADOConnection to nil
    ADOConnection.Free; // Does nothing since ADOConnection is nil
    

    You can see this by capturing it in a variable:

    var c: TADOConnection;
    c := ADOConnection;
    c.Free; // Frees ADOConnection and sets ADOConnection to nil
    c.Free; // Error: c is not set to nil
    

    That won’t work, even when ADOConnection is created at design time.

    Here’s an example with a TButton component that demonstrates how the behaviour you see for design-time components isn’t specific to design-time components:

    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;
    
    type
      TForm1 = class(TForm)
        procedure FormCreate(Sender: TObject);
      published
        Button: TButton;
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      Assert(not Assigned(Button));
      TButton.Create(Self).Name := 'Button'; // Button field gets set
      Assert(Assigned(Button));
      Button.Free;                           // Button field gets cleared
      Assert(not Assigned(Button));
      Button.Free;                           // Okay, Free may be called on nil values
    end;
    
    end.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been programming for some time, but I have some fundamental questions, one
have one time consuming step that flattens a bunch of files. basically i'd like
I have a fundamental design question in modelling the relationships between the entities for
I have one XML request which I need to modify (to XML) and then
I have one user (only one, all the others are fine) trying to update
I have one repo hosted at https://github.com/aikiframework/json . On my local copy, I added
I have one drop down list in my page, which contains two options. What
I have one problem with parsing *.docx document with OpenXML (C#). So, here's my
I have one model User and will be creating another one Category . Both
I have one table which contains events and dates, and another which contains the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.