473,549 Members | 2,741 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DefaultValue and String in Managed C++

Hi,
anyone an idea how to get DefaultValue's working for
String properties in managed C++.
I wrote a component in managed C++ which I plan to consume
in C#. Now the IDE keeps inserting null-assignments for
the string properties, while I've specified that NULL is
the default value. Other types work well.

thanks in advance,
Bram.
Nov 15 '05 #1
3 4192
Bram,

microsoft.publi c.dotnet.langua ges.vc is a better group for C++
questions.

Now the IDE keeps inserting null-assignments for
the string properties, while I've specified that NULL is
the default value. Other types work well.


Can you post your code?

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 15 '05 #2
Hi,
thanks for looking into my problem.
the code (managed C++) goes like this:

public __gc class SomeClass : public System::Compone ntModel::Compon ent
{
public:
SomeClass();
SomeClass(Syste m::ComponentMod el::IContainer container);
....
[DefaultValue(NU LL)]
__property String* get_Kind();
[DefaultValue(NU LL)]
__property String* set_Kind(String * value);
....
// other properties and methods
};

This class gets compiled into a component library. After dropping this
component on
a form (in C Sharp), the designer adds this line to the InitializeCompo nent
method of the form:

this.someClass1 .Kind = null;

while I explicitly stated that that's the default value. BTW, it works as
expected with other types
like int, short, ...

I don't get it.
I am not using VS.NET 2003. It might be solved already (if it's a bug).

regards,
Bram.
"Mattias Sjögren" <ma************ ********@mvps.o rg> wrote in message
news:Ok******** ******@tk2msftn gp13.phx.gbl...
Bram,

microsoft.publi c.dotnet.langua ges.vc is a better group for C++
questions.

Now the IDE keeps inserting null-assignments for
the string properties, while I've specified that NULL is
the default value. Other types work well.


Can you post your code?

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Nov 15 '05 #3
Bram,
[DefaultValue(NU LL)]


Since NULL is defined as 0, that compiles down to [DefaultValue(0)]
using the int constructor. And to managed code, 0 != null.

I tried some other possibilities, but wasn't able to get the same as
[DefaultValue(nu ll)] does in C#. That's partly due to a compiler bug.

I suggest you re-post your problem to the VC newsgroup, where it's
more likely to be seen by people who know this stuff.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3972
by: Craig Schneider | last post by:
// Is there any way to override the XML Serialization of the following SimpleClass // to turn off the DefaultValue of a boolean? Sure, I can override the DefaultValue from // true to false, but that is not what I want/need. I really need to just override the fact // that the developer ever supplied a DefaultValue. Setting an override...
1
1950
by: Mark | last post by:
How do I write the following code to set the default value? Me!xNum.DefaultValue = Me!XCurrency.DefaultValue = Me!XDate.DefaultValue = Me!XString.DefaultValue = Can I just put all the lines of code in the Form's AfterUpdate event? Thanks!
5
12749
by: bbrik | last post by:
Hi, I'm doing a control that has a custom color property and i want to set a default value. I tried several combinations using the DefaultValue atribute but it didn't work. It must be a constant, so i can't do: public Color MyColor { ... } I also tried:
1
1471
by: RR | last post by:
Hi, I want to set the defaultvalue of a property in a class. I know this is possible by the DefaultValue Attribute like this: public class Test { public Test(){}
5
1430
by: schneider | last post by:
Hello, Have an issue with a property using the DefaultValue(True) attribute. Imports System.ComponentModel Public Class Class1 Private m_testValue As Boolean
6
1906
by: Meelis Lilbok | last post by:
Hi Why does property default value not work? When i start my application and dont set value from properties window the value is always "nothing". Whats the point off DefualtValue then? Regards; Meelis
3
1993
by: MLH | last post by:
On frmVehicleEntryForm... I wanted to change the DefaultValue property of one of my textbox controls on a form from within code. I wanted the setting to be no setting - as if nothing had ever been entered there. First, I used Me!TowFee.DefaultValue = Null That returned an error, so I used Me!TowFee.DefaultValue = ""
10
3271
by: tony | last post by:
Hello!! I have some demo programs written in C# and they have this construction "" see below. I haven't seen this before so what does it mean ? public bool ShowDropDownButtons { get { return showDropDownButtons; }
25
5600
by: kstevens | last post by:
I have a sub to determine if overtime has come into play yet on a certain job. If (preapproved) overtime has started then the next (subform) record can automatically be populated from a query checking the overtime allowance. Here is the code. Private Sub OT_Test() If Forms!frmJobHourCostEmpName.TotalHours = 8 Then Me.OTJob.DefaultValue = True...
0
7450
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7720
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7957
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7470
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6043
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3500
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1941
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1059
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
763
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.