Solved

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
5
267 Views
Last Modified: 2012-05-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;
begin
  result := TFrame1.Create(Application);
end;

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);

var
  Frame: TFrame;

begin
  Frame := CreateFrame;
  Frame.Parent := self;
end;

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. :-)

-Graham
0
Comment
Question by:ghjm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 13

Accepted Solution

by:
Epsylon earned 1000 total points
ID: 2685046
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 2685065
It uses forms instead of frames because I used Delphi 4 at that time. But I think it is basically what you are looking for.

If you need assistance, please tell me.
0
 
LVL 1

Author Comment

by:ghjm
ID: 2685126
In fact, that will do nicely. I thought this question would be a great deal more difficult than it turned out to be. :-)

Post an answer so I can award points.
0
 
LVL 1

Author Comment

by:ghjm
ID: 2685139
Oh, they've changed the interface so you can accept a comment as an answer. Shows how long it's been since I've been here. :-)
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 2685154
Well.. there have been some lengthy threads and terrible headaches because of this issue, before that demo became what it is today.   :o]
0

Featured Post

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month5 days, 16 hours left to enroll

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question