[newbie] Default properties in Managed C++

M

Marco Jez

Hi everyone,

should I do something special to define the default value of a property in a
Managed C++ component or control class? Here is how I'm trying to do it:

[
DescriptionAttribute("Blah"),
CategoryAttribute("Behavior"),
DefaultValueAttribute(false)
]
__property bool get_Value() { return !internal_; }
__property void set_Value(bool v) { internal_ = !v; }

the field internal_ is initialized to true in the constructor so that
calling get_Value() would return false, which is the default value.
Well, this doesn't work... Whenever I add this component to a form in the
designer and look at the property browser, I notice that the above property
is displayed in bold style as if it was modified (but it isn't); trying to
restore the default value by menu results in an error message being
displayed.

What am I missing?

Cheers,
Marco
 
M

Mattias Sjögren

Marco,
What am I missing?

I think the reason for this is that the compiler ends up using the
DefaultValueAttribute constructor taking an int paramter instead of
the one with a bool parameter. I don't know if there's any workaround
for this, you may want to ask in the
microsoft.public.dotnet.languages.vc group.



Mattias
 
M

Marco Jez

Hi Mattias,
I think the reason for this is that the compiler ends up using the
DefaultValueAttribute constructor taking an int paramter instead of
the one with a bool parameter. I don't know if there's any workaround
for this, you may want to ask in the
microsoft.public.dotnet.languages.vc group.

It happens for other (integral) data types too, int included, as well as
pointers to Object (which default is set to zero). Thanks for pointing me to
the dotnet-VC group, I didn't even know of its existance... I'll post the
same question there.

Marco
 

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