title: Dynamically loaded BPL's sharing code / passing objects
body: <p>I was toying around with the idea of using dynamically loading BPL's and passing object instances from the main app to a method in a BPL. This poses a problem units between used by the application and by the BPL.  </p>
  
  <p>I wrote a small little prototype which did this and was curious how Delphi internally manages differences between classes defined in the app vs. the BPL.</p>
  
  <p>For example, say a basic Widget class like:</p>
  
  <pre><code>TmyWidget = class
  private
    fId:Integer;
    fDescription:String;
  public
    procedure DoSomething1();
  end;
  </code></pre>
  
  <p>Now the app and the BPL are built using the unit containing TmyWidget class. Later, something changes in TMyWidget and the app is rebuilt, but the BPL is not (or vice-versa.)  I added another method DoSomething2() and created an instance of TmyWidget in the app and passed it to the BPL for processing and in the basic example, it worked. But it's obviously fraught with potential problems.</p>
  
  <p>If another dynamically loaded BPL also uses TmyWidget then things get even more interesting.  It seems to work, but it definitely doesn't feel ideal. </p>
  
  <p>The main question is - how does one typically pass objects to and from the main application and DLLs or BPLs?  I've never attempted it before and likely for a good reason, but I've got this idea that lends itself to this approach...</p>
  
  <p>I'd imagine that the best approach is to serialize the object and pass those bytes over and deserialize it in the DLL/BPL with this process being mindful of potential version differences between the host and the dynamically loaded module but I was hoping the new SimpleSharedMem option might bring this new functionality without the overhead of serialization, but it seems to be not very useful unless you are strict in keeping the app and dll rebuilt on any shared code changes...but in this prototype, the app would stay fairly constant and the dynamically loaded modules would be changing frequently with functionality being added to TmyWidget. (The server app serves as the factory for building TmyWidget's based on client requests and the app would pass instances to the various modules for processing.)</p>