title: Differences in component streaming at runtime and design time
body: <p>I have some code that works properly at runtime but not in the IDE.  I am unable to find any documentation about how the loading of components is different that helps me.</p>
  <p>I have developed some components that define resources.  I have also developed a custom <code>TDataModule</code> descendant that holds these resource definitions.  As I want to be able to share the definitions between projects I have a simple <code>TComponent</code> descendent that can embed a <code>TDataModule</code> within it - the idea being that dropping the appropriate <code>TComponent</code> on a form or data module includes all of the resource definitions on the embedded <code>TDataModule</code>.</p>
  <p>This appears to be working as expected at run time, but not in the designer.</p>
  <p>I will try to explain the operation as concisely as possible.  There is lots of code involved but hopefully the following is enough to understand what's happening.</p>
  <p>There is a global <code>TDictionary</code> for registering the resource definitions.  The definitions are registered using a Binary UUID (a 16 byte array) as the key.  The UUID of the resource is set as a string representation (for ease of streaming).  When the string value is set the setter method checks on itself and upwards to see if it or any of the <code>Owner</code> <code>TComponent</code>s match <code>csLoading in ComponentState</code> and if any do the string value is saved temporarily.  If not the resource definition registers itself in the global dictionary.  (This is necessary because a random UUID is assigned in <code>AfterConstruction</code> at which point the <code>csLoading</code> flag is not set and so the parents must be checked).</p>
  <p>When a resource definition is fully streamed in the <code>Loaded</code> call the temporary string is used to set the UUID and the resource is registered.</p>
  <p>The <code>TComponent</code> that includes a <code>TDataModule</code> of definitions is based on a root class which has the following template code:</p>
  <pre><code>type
  TITIODataResourcesLoader = class(TDataModule)
   ...
  end;
  TITIODataResourcesLoaderClass = class of TITIODataResourcesLoader;
  
  TITIOResourceInclusion = class(TComponent)
  protected
    _pResources:    TITIODataResourcesLoader; 
    class function  _GetModuleClass(): TITIODatResourcesLoaderClass; virtual; abstract;
  public
    destructor Destroy; override;
    procedure AfterConstruction(); override;
  end;
  
  destructor TITIOResourceInclusion.Destroy;
  begin
    FreeAndNil(Self._pResources);
    inherited;
  end;
  
  procedure TITIOResourceInclusio.AfterConstruction;
  begin
    Self._pResources:=Self._GetModuleClass().Create(Self);
    inherited;
  end;
  </code></pre>
  <p>I have component editors for many of the resources which allow selection of a resource by enumerating the Values in the global <code>TDictionary</code> for that class of resource.  So, for example, one of the resource definition types is the definition of a database table and another of the resource definition types is the definition of a database table join.  In the component editor for the definition of the join the user can chose which tables to join by selecting any of the tables that are registered in the global <code>TDictionary</code>.</p>
  <p>In a test project that has a <code>TITIODataResourcesLoader</code> which defines a number of table types, and a <code>TITIOResourceInclusion</code> that includes another <code>TITIODataResourcesLoader</code> (which is in a different BPL file) then at runtime the join editor (which is a VCL Form) will show all of the tables, but in the designer only the tables which are defined on the test project's <code>TITIODataResourcesLoader</code> are available.  If I open the <code>TITIODataResourcesLoader</code> included in the BPL file then the resources on that are registered and selectable in the designer on the test project's <code>TITIODataResourcesLoader</code>.</p>
  <p>So it appears that at runtime the streaming of the <code>TITIOResourceInclusion</code> does not cause the components in the included <code>TITIODataResourcesLoader</code> to be registered, <em>but at runtime it does work as expected</em>.</p>
  <p>So my question and confusion is: How is the streaming of components different in the Designer?</p>