• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 253
  • Last Modified:

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

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
westy100697
Asked:
westy100697
  • 6
  • 5
  • 2
  • +3
1 Solution
 
JaccoCommented:
I'm interested too.. so let me try.

Regards Jacco
0
 
westy100697Author Commented:
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
 
viktornetCommented:
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
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
westy100697Author Commented:
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
 
westy100697Author Commented:
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
 
JaccoCommented:
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
 
westy100697Author Commented:
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
 
peed112097Commented:
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
 
peed112097Commented:
In the function GetSecretary it should be TMySecretary.Create....., sorry!
/Per
0
 
JaccoCommented:
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
 
westy100697Author Commented:
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
 
JaccoCommented:
Nope not yet...

peed will send me his code :)

Regards Jacco
0
 
JaccoCommented:
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
 
Hagen040798Commented:
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
 
westy100697Author Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 5
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now