Component constructors, is there another one ?

E

Edward Diener

In the Writing Components topic of Mr. Grimes' book on Managed C++, he
states that if a component is ultimately derived from either
MarshalByRefObject or MarshalByValueComponent, it should implement a second
constructor which takes an IContainer in order to add itself to a component
container. While I understand that components have containers, I have seen
no documentation regarding a second constructor to a component. Does it
really exist or is this an error in Mr. Grimes' nearly flawless technical
writing. If this second constructor actually exists:

1) What container(s) creates a component calling this second constructor ?
2) Why does MarshalByRefObject or MarshalByValueComponent not have this
second constructor which would automatically add itself to an IContainer
derived object when a derived class calls down to one of these bases in its
constructor ?
3) Where in the MSDN documentation is this second constructor documented ?
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hi Edward,
1) What container(s) creates a component calling this second constructor ?

Most likely these are VS .NET designers (WinForms and WebForms)
3) Where in the MSDN documentation is this second constructor documented ?

Well, I found it mentioned here:

"Walkthrough: Authoring a Component with Visual C#"

But, indeed, it seems that this constructor is not well explained in the
MSDN. I suppose it is used by the designers (and is automatically added when
you add a new component to your project). Here's an article on CodeProject:

http://www.codeproject.com/dotnet/disposable_components.asp

that can probably shed more light on this topic.
 
E

Edward Diener

Dmitriy said:
Hi Edward,


Most likely these are VS .NET designers (WinForms and WebForms)


Well, I found it mentioned here:

"Walkthrough: Authoring a Component with Visual C#"

But, indeed, it seems that this constructor is not well explained in
the MSDN. I suppose it is used by the designers (and is automatically
added when you add a new component to your project). Here's an
article on CodeProject:

http://www.codeproject.com/dotnet/disposable_components.asp

that can probably shed more light on this topic.

Thanks for the information. It does seem as if this second constructor
should be documented in MSDN for component developers. Yet when one looks at
System::ComponentModel::Component, there is clearly only a single
constructor mentioned. Does this mean that if I add this constructor for my
component, I still invoke the default constructor for
System::ComponentModel::Component in my base class ?
 

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