1. Home
  2. Computing & Technology
  3. Delphi Programming

A warning on dynamically instantiating components

By , About.com Guide

6 of 10

Performance Hit on Destruction - 1

When the TTable instance is destroyed (the call to "Free" in the Finally block), ultimately the TComponent destructor is called (Free checks the instance to see if it's non-nil and then calls Destroy). TComponent.Destroy looks like this:

destructor TComponent.Destroy;
var
   j: Integer;
begin
   if FFreeNotifies <> nil then
   begin
     for j := 0 to FFreeNotifies.Count - 1 do
       TComponent(FFreeNotifies[j]).Notification(Self, opRemove) ;
     FFreeNotifies.Free;
     FFreeNotifies := nil;
   end;
   Destroying;
   DestroyComponents;
   if FOwner <> nil then FOwner.RemoveComponent(Self) ;
   inherited Destroy;
end;

Notice near the end of this method the check to see if "FOwner <> nil", followed by the call to the owner's RemoveComponent method. In other words, when this TTable instance was created, an owner was specified in the constructor, then we'll call that owner's RemoveComponent method later when the TTable instance is destroyed. RemoveComponent looks like this...

Explore Delphi Programming
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Using VCL Components
  5. Run time VCL creation
  6. A warning on dynamically instantiating Delphi components

©2009 About.com, a part of The New York Times Company.

All rights reserved.