Discussion:
Load Form from DLL to MDI Child
(too old to reply)
Andy
2008-07-19 19:27:38 UTC
Permalink
I have an MDI application. I would like to load a form in a DLL
into a child form and making the child form the parent form of
the DLL. I am able to use LoadLibrary in the child form to
load the DLL but I'm not sure how to make the DLL form
fill up the child form. Also, in subsequent child forms, is it
okay that many instances of the DLL is loaded?

Any help is greatly appreciated.

Andy
Peter Below (TeamB)
2008-07-20 09:16:43 UTC
Permalink
I have an MDI application. I would like to load a form in a DLL into
a child form and making the child form the parent form of the DLL. I
am able to use LoadLibrary in the child form to load the DLL but I'm
not sure how to make the DLL form fill up the child form. Also, in
subsequent child forms, is it okay that many instances of the DLL is
loaded? Any help is greatly appreciated. Andy
Why have you posted that question to the thirdpartytools group?
borland.public.delphi.language.delphi.general would be a better fit, I
think.

Anyway: if you want to share objects between a Delphi host application
and a Delphi DLL you need to use packages, not DLLs (or build the DLLs
with run-time packages, using the standard RTL and VCL packages). If
you do not use packages the host applications message loop will not
recognize the embedded forms and the controls on them as VCL controls
and will not do any of the message preprocessing a number of VCL
features depend on. The host app also needs to be build with packages,
of course. You can load packages dynamically using the LoadPackage
function and it can export functions like a DLL (exports clauses, in a
unit, not in the dpk file) and those can be linked to via
GetProcAddress, using the package handle as first parameter.
--
Peter Below (TeamB)
Don't be a vampire (http://slash7.com/pages/vampires),
use the newsgroup archives :
http://www.tamaracka.com/search.htm
http://groups.google.com
Andy
2008-07-20 09:34:10 UTC
Permalink
Hi Peter,

Thanks for the response. I chose this newsgroup hoping there would be
an easy way to do this using a third-party component :)

I have actually done this in packages per your suggestion. I am still in
need to know how to make the form from the package to be a slave
of the application form. I was hoping to set the parent of the form from
the package to the host application, and be able to set the Align to
alClient.

Any way to do this?

Thanks in advance.

Andy
Post by Peter Below (TeamB)
I have an MDI application. I would like to load a form in a DLL into
a child form and making the child form the parent form of the DLL. I
am able to use LoadLibrary in the child form to load the DLL but I'm
not sure how to make the DLL form fill up the child form. Also, in
subsequent child forms, is it okay that many instances of the DLL is
loaded? Any help is greatly appreciated. Andy
Why have you posted that question to the thirdpartytools group?
borland.public.delphi.language.delphi.general would be a better fit, I
think.
Anyway: if you want to share objects between a Delphi host application
and a Delphi DLL you need to use packages, not DLLs (or build the DLLs
with run-time packages, using the standard RTL and VCL packages). If
you do not use packages the host applications message loop will not
recognize the embedded forms and the controls on them as VCL controls
and will not do any of the message preprocessing a number of VCL
features depend on. The host app also needs to be build with packages,
of course. You can load packages dynamically using the LoadPackage
function and it can export functions like a DLL (exports clauses, in a
unit, not in the dpk file) and those can be linked to via
GetProcAddress, using the package handle as first parameter.
--
Peter Below (TeamB)
Don't be a vampire (http://slash7.com/pages/vampires),
http://www.tamaracka.com/search.htm
http://groups.google.com
Peter Below (TeamB)
2008-07-21 17:50:18 UTC
Permalink
Post by Andy
I have actually done this in packages per your suggestion. I am still
in need to know how to make the form from the package to be a slave
of the application form. I was hoping to set the parent of the form
from the package to the host application, and be able to set the
Align to alClient.
Any way to do this?
Exactly the way you describe above: set the Parent property of the form
instance create by the package to the MDI child (or panel on it) and
set the Align property of the form to alClient.

Note that this is what you requested in your original post (using an
MDI child window in the host app as parent for a DLL form) but it may
not be what you actually intend to do <g>. If you want to have a *MDI
child* contained in the DLL/package parented to the host EXEs *MDI main
form* this is not the way to go. Instead you only need to set the
package forms Formstyle to fsMDIChild, like you would do it for a child
form that is part of the host EXE directly. Since both modules, build
with packages, use the same instance of the Forms unit they also use
the same instance of Application, so the package form has no problem
finding the main form it is supposed to live in. This is something you
cannot do with a non-packaged DLL at all, since it would use a
different instance of Application, with no main form defined.
--
Peter Below (TeamB)
Don't be a vampire (http://slash7.com/pages/vampires),
use the newsgroup archives :
http://www.tamaracka.com/search.htm
http://groups.google.com
Andy
2008-07-22 04:41:07 UTC
Permalink
Hi Peter,

Thanks for the guidance. I will definitely go back to the drawing board on
this.

Andy
Post by Peter Below (TeamB)
Post by Andy
I have actually done this in packages per your suggestion. I am still
in need to know how to make the form from the package to be a slave
of the application form. I was hoping to set the parent of the form
from the package to the host application, and be able to set the
Align to alClient.
Any way to do this?
Exactly the way you describe above: set the Parent property of the form
instance create by the package to the MDI child (or panel on it) and
set the Align property of the form to alClient.
Note that this is what you requested in your original post (using an
MDI child window in the host app as parent for a DLL form) but it may
not be what you actually intend to do <g>. If you want to have a *MDI
child* contained in the DLL/package parented to the host EXEs *MDI main
form* this is not the way to go. Instead you only need to set the
package forms Formstyle to fsMDIChild, like you would do it for a child
form that is part of the host EXE directly. Since both modules, build
with packages, use the same instance of the Forms unit they also use
the same instance of Application, so the package form has no problem
finding the main form it is supposed to live in. This is something you
cannot do with a non-packaged DLL at all, since it would use a
different instance of Application, with no main form defined.
--
Peter Below (TeamB)
Don't be a vampire (http://slash7.com/pages/vampires),
http://www.tamaracka.com/search.htm
http://groups.google.com
Loading...