?
Solved

Help..Mapping Application.Handle!!

Posted on 1998-12-10
7
Medium Priority
?
200 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. 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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses

771 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