[newbie] Default properties in Managed C++

  • Thread starter Thread starter Marco Jez
  • Start date Start date
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
 
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
 
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
 
Back
Top