Solved

Help..Mapping Application.Handle!!

Posted on 1998-12-10
7
198 Views
Last Modified: 2010-04-04
My question this....

 In delphi 3 I am trying to assign the Main Executables Application.Handle(Mainform.Handle) to a Dll. How do you do this. I know how to access a procedure in a Dll and use it but how do you assign and EXE's Application.Handle to a Dll. This is pretty important for what I require to do. Any ideas??

The Delphi help says "When writing a DLL that uses VCL forms, assign the window handle of the host EXE’s main window to the DLL’s Application.Handle property. This makes the DLL’s form part of the host application. Never assign to Application.Handle in an EXE."

Easier said then done I say....
Any help would be much appreciated.

Thanks WESTY :|
0
Comment
Question by:westy100697
[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
  • 4
  • 3
7 Comments
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1350511
Do this in the DLL

Procedure SetApplication(TheApplication : TApplication); Stdcall;

begin
  Application := TheApplication;
end;

Then call it from your application like this (after declaring it in the DLL interface as the usual manner...):

SetApplication(Application); // And there you have it.

Cheers,

Raymond.

0
 

Author Comment

by:westy100697
ID: 1350512
rwilson,
        This seems to work well with a little fiddling. The only problem now is that it doesn't want to release/free the application when i exit. Get a runtime error?? It is very strange
but I think it stems from the Dll. Not unloading properly. I thank you very much and am awarding you the points but if know of a solution for that runtime error I will increase points to 80. By the way, just thought I should mention this it is an MDI application that loads a Dll full of MDI Child forms. This is the reason I needed some way of loading the Application object into the Dll. Anyway if you can help let me know otherwise I will just give ya the 50 eh!

Regards
WESTY :)
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1350513
Westy,

The error is becasue the DLL will try to free is application object and so will the application - but now they are the same object.

Change the code so it is like this:

var
  SaveApplication : TApplication;

Procedure SetApplication(TheApplication : TApplication); Stdcall;

    begin
      SaveApplication := Application;
      Application := TheApplication;
    end;

Remember to restore the application again before exiting.

Williams2 et al have worked up a complete solution to the MDI forms in DLL problem - it may be found in http://www.experts-exchange.com/topics/comp/lang/delphi/Q.10104327 which solves other problems with MDI forms in DLLs.

I hope this helps...

Cheers,

Raymond
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:westy100697
ID: 1350514
rwilson,
           I appreciate the swift response on the problem and will award you 80 points okay. I will reject this answer for 50 points bump it up to 80 and you lock it again and I will award the points. Thanks again.

WESTY :)
0
 

Author Comment

by:westy100697
ID: 1350515
I have upped the points rwilson. Lock it again.

WESTy
0
 

Author Comment

by:westy100697
ID: 1350516
I have upped the points rwilson. Lock it again.

WESTy
0
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 80 total points
ID: 1350517
Thanks Westy!

Cheers,

Raymond.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

739 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