.dll and forms

J

Jaime Lucci

Hi, how've you been?

I'm trying to do a .dll that would be able to manage forms from an
independient project. The dll has a method that receive a parameter which is
the form I want to manage. The problem is that I have to pass the instancied
form as parameter instead of its name. When I have to manage many forms, it
will be necessary to instance all forms, and it minus the performance of my
project.

What I do is:

myclass.mymethod(new form1).
myclass.mymethod(new form2).
myclass.mymethod(new form3).
....
myclass.mymethod(new formN).

How can I do to prevent this and pass as a parameter only the form name
instead of the instanced form? If I pass the class name I have an error.

I hope you understand my problem and my english.

Thanks.

Jaime Lucci
(e-mail address removed)
Salta, Argentina
 
O

Ollie Riches

why don't you pass the form type as a string and use reflection to create
the instance of the form.

HTH

Ollie Riches
 
R

Richard Grimes

Jaime said:
Hi, how've you been?

Not particularly happy, but that's irrelevant here
I'm trying to do a .dll that would be able to manage forms from an
independient project. The dll has a method that receive a parameter
which is the form I want to manage. The problem is that I have to
pass the instancied form as parameter instead of its name. When I
have to manage many forms, it will be necessary to instance all
forms, and it minus the performance of my project.

Have you tested this out?

You see, when you create a form with new, you don't actually create the
window. All you do is create the form object and hence any objects it
has as fields. The actual window (and any controls it contains) is not
created until the form is first made visible. If you do not make the
form visible before passing it to your method then the window will not
be created. Note that Visual Studio designers use InitializeComponent to
do most of the initialization. If you move that out of the constructor
to a public method then when you create the form object the fields will
not be initialized, so you do not get that overhead. Your method can
simply call the public initialization method before it makes the form
visible.

The alternative, using reflection, is likely to have fairly poor
performance because every access to the form object will require a call
through reflection.

Given the choice I would *not* use reflection in this situation, instead
I would pass the uninitialized, not-yet-made-visible form object.

Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top