Solved

Help Anyone...About MDI Childs in Dll's

Posted on 1998-10-02
16
215 Views
Last Modified: 2010-04-06
Hello there,
            I have asked several questions recently regarding the proper procedure for getting MDI Childs to work in Dlls. I have had a response from Vik but was wondering does anyone know where to find good example code on how to implement MDI Child Forms in Dll's and to have it work successfully. ie Without getting No MDI Childs currently Active. Anyone ???

WESTY :(
0
Comment
Question by:westy100697
  • 6
  • 5
  • 2
  • +3
16 Comments
 
LVL 10

Expert Comment

by:Jacco
ID: 1341509
I'm interested too.. so let me try.

Regards Jacco
0
 

Author Comment

by:westy100697
ID: 1341510
Hi Jacco,
              Okay then see how you go.It seems to be a challenging problem from what I have seen on the Newsgroups around the net.

WESTY :|
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1341511
Hello Westy!!!

Haven't had much time lately 'cause I got lotsa things to study for... I have a few spare minutes to answer some questions that don't need much of a work and don't need a resaerch onit.... That's why couldn't be able to answer the question... Anyway, if I find something I'll send it to ya...

///VIk :-|
0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1341512
0
 

Author Comment

by:westy100697
ID: 1341513
Hi there,
             Thanks for the comments and links. Will have a look at them ASAP and let you know if they were a help. Thanks for answering the question too. I got an e-mail from a newsgroup question I posted and it suggested I pass the Main exe's Application variable to the Dll. Something to do with Dll's see there Application mainform as having formstyle
fsNormal. I am investigating this further and have had no success yet in getting it to pass from the EXE to the Dll but am trying. As with everyone time is of the escence in sorting  out what seems a simple problem at first.

Vik,
      No worries I understand study takes up a lot of time. If you do find find something it would be muchly appreciated. Just put up another question to see if anyone else could come up with some extra help.

Ronit,
         Thanks for the links I will look at them and let you know how I go.

Thanks
 WESTY :)
0
 

Author Comment

by:westy100697
ID: 1341514
Ronit,
         I tried the the code form the link
                      http://developers.href.com/NEWS:ARTICLE::waArticle.347355
   and it was very easy to implement. However I get exactly the same problem as before.
"Cannot Create Form. No MDI Child currently Active". It seems to pass the Application variable no worries at all but as soon as it tries TForm1.Create(AOwner) the error occurs in the Dll. Boy oh boy is this problem a tough one to solve.

Regards
  WESTY :)

PS. Am yet to try the second link...
0
 
LVL 10

Expert Comment

by:Jacco
ID: 1341515
westy:

I have tried passing the Application variable but that didn't work.

There is also a global variable hInstance which I tried to pass but that didn't work as well. I have seen that also a global windows variable hWindowMenu is used somewhere in the form creation.

I haven't found yet where the Exception is generated.

My next approach will be making a base class of the MDIChild window first which I use in the main exe and the dll. In the DLL I will derive a class from it which implements some abstract methods.

Regards Jacco.

(I do not have much time to puzzle. But the problem is interesting enough!)
0
 

Author Comment

by:westy100697
ID: 1341516
Jacco / Everyone,
                          I have looked at the second link given by Ronit above and from what I can gather from the info you actually cannot use the Application Variable as it is the wrong place to derive the Application.Mainform info from. I haven't actually tried to use this code yet but it looks like a good explanation of the problem. My goodness they sure made an MDI Application with MDI Child Dll's hard to implement. Will keep you posted on how I get on with the second link.

 WESTY  :)
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Accepted Solution

by:
peed112097 earned 100 total points
ID: 1341517
Hi!

I had the same problem before, but I think I got it. I'll put som code down to explain for it self.
The MDIApp load's the library and then creates a class that from a method creates the window. I don't care about the Application.handle, just make sure you pass the owner right. I hope this helps!
/Per

The MDIApplication:------------------------------------------------------------------------------
..
type
   TMyClass = class....
   end;
  TGetSecretary = function(theOwner : TComponent; theAppHandle : HWND) : TSecretary; stdCall;
..
Procedure loadMyLibrary;
var
   packhandle : integer;
   aGetSec : TGetSecretary;
begin
       packHandle := LoadLibrary('ProjectDll.dll');
       @aGetSec := GetProcAddress(packHandle, 'getSecretary');
       mySecretary := aGetSec(self, Application.Handle); // function that creates a class
end;

procedure ShowChildWin;
begin
    mySecretary.showWin;
end;

The secretary class ----------------------------------------------------------------------------
type
  class TMySecretary = class(TSecretary)
     procedure .....
    ......
  end;
  function GetSecretary(theOwner : TComponent; theAppHandle : HWND) : TSecretary; stdCall;

implementation


function getSecretary(theOwner : TComponent; theAppHandle : HWND) : TSecretary;
begin
     Result := TSecretary.create(theOwner, theAppHandle);
end;
{ TSecretary }

constructor TMySecretary.create(theOwner : TComponent; theAppHandle: HWND);
begin
     inherited create;
     myAppHandle := theAppHandle;
     myOwner := theOwner;
end;

procedure showWin;
begin
     if not Assigned(Form2) then
     begin
          Form2 := TForm2.Create(myOwner);
          Form2.Show;
     end;
end;


The child win(TForm2) ------------------------------------------------------------------
just a plain form with formstyle = fsMDIChild



0
 

Expert Comment

by:peed112097
ID: 1341518
In the function GetSecretary it should be TMySecretary.Create....., sorry!
/Per
0
 
LVL 10

Expert Comment

by:Jacco
ID: 1341519
peed: I cannot accomplish this..... Can you post a complete project source? I havce tried it this way... Can't get it to work

Regards Jacco
0
 

Author Comment

by:westy100697
ID: 1341520
Peed,
         Thanks for the info. I will test it out and see how it goes. One question tho, it looks like you just have all the code in your Main Application. Is this correct? In the dll you just have a collection of forms. Any export procedures?
When I build dll's I include a unit which has all the form create procedures within it. It looks as tho this is not necessary as you are calling the Create code from the Main EXE.
Could you please just clear this up a little for me.....

Thanks again and I will see how it goes,

WESTY :)

PS. I see Jacco has had a go. Any success yet Jacco?

0
 
LVL 10

Expert Comment

by:Jacco
ID: 1341521
Nope not yet...

peed will send me his code :)

Regards Jacco
0
 
LVL 10

Expert Comment

by:Jacco
ID: 1341522
I guess the code is for D3... :( I work with D2.

The problem lies in a couple of things:

The Application variable. (which is used for retrieving the MainForm)
The Screen variable. (which is used to store the Form in when created)
The hInstance variable. (which is used to create the windows classes).

The screen variable is private. No means of adding the form when created in the DLL. We have to hack there.

The Application variable is no problem. I overrode the CreateWindowHandle, DestroyWindowHandle and CreateParams of the MDI.

hInstance is no problem either.

InitInheritedComponent causes some exception which I tried to catch in the DLL but didn't succeed.

westy: Can you get peed's code to work?

Regards Jacco.
0
 
LVL 2

Expert Comment

by:Hagen040798
ID: 1341523
Hi

When your compile the Application and all DLL's with the Package-Options and then load the DLL's, then used all DLL's the same TApplication object.
0
 

Author Comment

by:westy100697
ID: 1341524
Hagen / All,
                 Sorry I haven't gotten back on this question but am working 15hour days and haven't had time to respond.

Hagen :  Can you clarify a bit more on what you mean. I don't quite follow..

Jacco :  I haven't tries peed's code yet but am hoping to try it later tonite.. See if it works and will let you know if i have any success....

Regards  WESTY :)
         
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Intraweb submit form as a POST request 4 230
PDF library for Delphi 2 89
Delphi XE10, MySQL Query 4 109
Dev Express grid collapse 2 35
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…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now