If you release the component, its corresponding field with the owner will be cleared. If you add the ADOConnection development 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
This will not work even when an ADOConnection is created at design time.
Here is an example with the TButton component, which demonstrates how the behavior that you see for development-time components does not apply to development-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.
source share