Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 1998-10-02
16
Medium Priority
?
246 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
Independent Software Vendors: 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: 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
 

Accepted Solution

by:
peed112097 earned 200 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Integration Management Part 2
Suggested Courses

916 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