Is it possible to instantiate a TFrame from a DLL where the calling EXE is not linked to the frame unit?
Posted on 2000-04-04
I'm interested in writing an application that does 'snap-ins' similar to, say, Microsoft Management Console, or Novell NetWare Administrator. The idea is that there would be a small framework EXE that searches through a directory full of DLLs to find its GUI functionality. Each DLL would implement one (or perhaps several) TFrame-descended class. The EXE would then display the frame on a panel somewhere.
The problem is, even in very simple sample code, if you instantiate a TFrame in a DLL and pass a pointer to it back to the EXE, bad things happen. I suspect the problem is that the VCL linked into the EXE doesn't know about the classes in the DLL, therefore can't display them. Or something. Anyway, it doesn't work.
Steps to reproduce what I'm seeing:
In Delphi 5, create two projects. The first is a DLL. Create a frame within the DLL form and put some random thing on it, like a label that says "this is the frame." Then export a function from the DLL that looks like this:
function CreateFrame: TFrame; safecall;
result := TFrame1.Create(Application);
Note that this means Forms must be in the uses clause of the DLL main library unit. I've tried it with and without. I've also tried it with and without ShareMem present in the uses clauses.
Then, create a new application, put a button on the main form, and add code to the button that looks like this:
function CreateFrame: TFrame; safecall; external 'dll.dll';
procedure TForm1.Button1Click(Sender: TObject);
Frame := CreateFrame;
Frame.Parent := self;
When I run the project, CreateFrame works correctly (ie, it returns a pointer); but on the Frame.Parent assignment, I get "cannot assign a TFont to a TFont" followed by GPFs, exceptions, etc.
I'll give 200 points to someone who can establish authoritatively that this is impossible - or 1000 points to someone who can make it work. :-)