How does one specify in a component that a property is a pointer to another
component ? How is this different from a property that is actually an
embedded component ? Finally how is one notified in a component when another
component is destroyed ?
I have a managed component called P. Let us say that C is another managed
component. If on P I have:
__property C * get_CComp();
__property void set_CComp(C *);
Does this mean that my property is a pointer to CComp or does this mean that
my property is an actual CComp ? If the former, which seems like it should
be correct, how would I have a property which is an embedded CComp, since
CComp is a component which must be accessed through its pointer ? Or is is
that only __value classes can be embedded in a component and not another
__gc class ?
If CComp * is a pointer to a component, how I am notified if CComp is
destroyed, or is a moot point since as long as I hold a pointer to CComp it
is never destroyed by the GC ? If the latter is the case, I may still be
trying to use some functionality on CComp after it has been, let's say,
removed from a windows form. How does this effect my pointer, or does the
windows form container automatically set CComp back to 0 if that happens ? 2 1738
Hi Edward, How does one specify in a component that a property is a pointer to
another component ? How is this different from a property that is actually an embedded component ?
What do you understand by each of those sentences? Are you talking about
asociation versus composition? If so, why would both patterns be
distinguishable at the property level?
Finally how is one notified in a component when another component is destroyed ?
That depends on whether actual component containment (in the sense that the
..NET Framework Component model works) is actually taking place or not. I have a managed component called P. Let us say that C is another managed component. If on P I have:
__property C * get_CComp(); __property void set_CComp(C *);
Does this mean that my property is a pointer to CComp or does this mean
that my property is an actual CComp ?
All it means is that it returns a reference to the actual object (let's
assume for now that we're only talking about reference types). No more, no
less.
If the former, which seems like it should be correct, how would I have a property which is an embedded CComp, since CComp is a component which must be accessed through its pointer ? Or is is that only __value classes can be embedded in a component and not another __gc class ?
If CComp * is a pointer to a component, how I am notified if CComp is destroyed, or is a moot point since as long as I hold a pointer to CComp
it is never destroyed by the GC ?
Yiou could hook them up through events, if you feel like it. However, let us
question another thing: What do you understand by "destroyed"? If you mean
just Garbage Collector, then the answer is: you don't know when it might be
collected. However, you are definitely assured that the CComp instance will
not be collected as long as your object is being referenced by a root
somewhere else.
I strongly suggest you look for the GC articles by Jeffrey Richter that
appeared a couple of years back in MSDN Magazine. Also, check out the use of
the IDisposable pattern/interface. And finally, make sure to clearly
separate the notion of referencing objects and containing components. Those
are two pretty different things, specially if you're talking .NET
--
Tomas Restrepo to****@mvps.org
Tomas Restrepo (MVP) wrote: Hi Edward,
How does one specify in a component that a property is a pointer to another component ? How is this different from a property that is actually an embedded component ? What do you understand by each of those sentences? Are you talking about asociation versus composition? If so, why would both patterns be distinguishable at the property level?
I want to have a property which points to another component so that setting
the property in the Window Forms Designer means dropping the other component
on the form and then setting the property of my component to the instance of
the other component. My guess is that this means that my property is
OtherComponent * in MC++ which is equivalent to a reference in C#.
Now I want to have a property which is the other component itself, what I
call an embedded component if this is the correct term. Then when the user
goes to set my property, he is really setting the internal properties of the
embedded component However, components can only be created on the GC heap so
having a property of OtherComponent type appears impossible. I am guessing
that to have this sort of embedded component means that the type must really
be a value class and not a component, and in only this way am I able to
embed another class as a property. Finally how is one notified in a component when another component is destroyed ? That depends on whether actual component containment (in the sense that the .NET Framework Component model works) is actually taking place or not.
I have a managed component called P. Let us say that C is another managed component. If on P I have:
__property C * get_CComp(); __property void set_CComp(C *);
Does this mean that my property is a pointer to CComp or does this mean that my property is an actual CComp ?
All it means is that it returns a reference to the actual object (let's assume for now that we're only talking about reference types). No more, no less.
OK, understood. In the Windows Form Designer, therefore, the end-user could
only set the property to a separately instantiated object of CComp which has
been dropped on the form. If the former, which seems like it should be correct, how would I have a property which is an embedded CComp, since CComp is a component which must be accessed through its pointer ? Or is is that only __value classes can be embedded in a component and not another __gc class ?
If CComp * is a pointer to a component, how I am notified if CComp is destroyed, or is a moot point since as long as I hold a pointer to CComp it is never destroyed by the GC ? Yiou could hook them up through events, if you feel like it. However, let us question another thing: What do you understand by "destroyed"? If you mean just Garbage Collector, then the answer is: you don't know when it might be collected. However, you are definitely assured that the CComp instance will not be collected as long as your object is being referenced by a root somewhere else.
Here is the scenario. The user drops my component on a form. The user drops
another component on a form. the user sets my component pointer ( reference
in C# ) property to the other component. This sets my property's pointer to
the instance of the other component on the GC heap. Now the user removes the
other component from the form. What happens to my property ? Is my property
set function automatically called with a 0 pointer ?
Now the run-time scenario. The same as before but instead of removing the
other component from the form, the program calls delete on the other
component's instance. I know this means that the other component still
exists on the GC heap, but its destructor has been called effectively
rendering it "destroyed" for all practical purposes. What happens to my
component's property ? If it is not set back to 0, my component still thinks
that the other component is live and may attempt to call one of its methods
or access one of it properties. I strongly suggest you look for the GC articles by Jeffrey Richter that appeared a couple of years back in MSDN Magazine.
Do you know what the year/month or for these. I can more easily find them
online if you do, else I will try to search under Richter's name if it is
possible. BTW Richter is the best writer on Microsoft technology ever IMHO.
Also, check out the use of the IDisposable pattern/interface.
I understandable IDisposable.
And finally, make sure to clearly separate the notion of referencing objects and containing components. Those are two pretty different things, specially if you're talking .NET
That is what I was trying to do with this question. I don't see how
components are contained, however, unless they are __value classes. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Edward Diener |
last post by:
Since a C++ using declaration isn't allowed in MC++, is there a way to
specify that a property, method, event, or field's access can be changed in
a derived class, ie. is protected in one class and...
|
by: Edward Diener |
last post by:
In C++ an overridden virtual function in a derived class must have the exact
same signature of the function which is overridden in the base class, except
for the return type which may return a...
|
by: Edward Diener |
last post by:
In MC++ properties are syntactically created through member functions
declared with the __property keyword and using set_ and get_ naming
conventions. Given that a property is specified in this...
|
by: Arnaud Debaene |
last post by:
Hello,
I think I found a bug in VC 7.1 concerning destruction of stack
objects when linking a static, non managed, C++ library within a
managed C++ application. Here is a repro case :
1)...
|
by: Peter Insley via .NET 247 |
last post by:
Hi, have been searching for an answer for this for quite a while,I would be greatfull for any help.
We are developing a codebase that of components that we wouldlike to be able to write in MC++ or...
|
by: Jordan Bowness |
last post by:
I make a similar post in another newsgroup, but this example is
simplified somewhat.
I have a component (cmpMyComponent) with 2 properties. The 1st property
is a string value (Description) and...
|
by: WebSnozz |
last post by:
I have an application written in C that does a lot of low level stuff.
It does a lot of things like casting from void*'s. I want to create a
new GUI for it in either C# or MC++, but reuse the...
|
by: Andrus |
last post by:
I'm implementing entity object which should populate its properties from
database when property is first referenced.
In RDL reports I use object properties like
MyObject.MyProperty
MyObject...
|
by: =?Utf-8?B?QmlsbCBTcGFobg==?= |
last post by:
I have an abstract base class defined in an MC++ class library. I then
create a descendent class in a C# class library. This seems to work OK with
the exception of one of the abstract member...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |