[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Help..Mapping Application.Handle!!

Posted on 1998-12-10
7
Medium Priority
?
205 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
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 320 total points
ID: 1350517
Thanks Westy!

Cheers,

Raymond.
0

Featured Post

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!

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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month17 days, 15 hours left to enroll

829 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