|
The compiler complains because you are trying to add a number with a reference (a reference is like a C++ pointer, but it "points" to a garbage collected object).
unsigned int ^ is a reference to an unsigned int , so you should dereference it to get the actual value:
sagXArray = gcnew array<double>(*pointParam + 2);
But this will not work if you pass a number as a string (ex. "135"), you have to convert the string to a number using the method int::Parse :
int pointParam = int::Parse(dictParameters[POINT_PARAM]);
sagXArray = gcnew array<double>(pointParam + 2); Note that in this case I'm not dereferencing pointParam because it is declared as an int .
Hope it helps!
|
|
|
|
|
Hi Ghydo,
So, "reinterpret_cast" will cast to a reference (pointer), while "int::Parse" casts to a value.
Is that correct?
Thanks for the help!
regards,
Bert
|
|
|
|
|
Hi Bert,
reinterpret_cast can cast to anything you want: to cast to a unsigned int you can use reinterpret_cast<unsigned int^> . (MSDN[^])
int::Parse is a method that takes a string and converts it (not cast) into its integer value (string "135" --> int 135).
If dictParameters[POINT_PARAM] is an array of unsigned int ^ your cast was correct and you should dereference pointParam to obtain the value, but if it is an array of string you have to convert it using int::Parse .
How is dictParameters defined?
I hope it is clearer!
|
|
|
|
|
I'm almost brand new to C++ so I'm hoping someone can help me out. I'm using Visual Studio 2008 to create a C++ Windows Form application, and I want to display the current time in place of some static text I was previously using as one of my Label controls. I've spent some time poking around and I think I'm missing something basic.
I was trying something like this:
this->label1->Text = System::DateTime::Now;
and something a little more complexe like this:
this->label1->Text = (System::DateTime::Now.ToString("T"));
But no matter how I manipulate the line, either the code editor or the design editor within Visual Basic Studio barks at me. On my first example shown above, the code editor tells me it "....cannot convert parameter 1 from 'System::DateTime' to 'System::String ^'" while the design editor is just fine. And on my second example shown above, the design editor tells me "C++ CodeDOM parser error:Line:76, Column:56 --- Internal Error" while the code editor is just fine.
So can someone help me out here and let me know what I'm missing? My goal is to just have something like "5:11:45 PM" show up as the text of my Label control when a user runs the program.
Thanks!
|
|
|
|
|
I would start by dropping the parentheses around the righthand side.
|
|
|
|
|
If I change it to this: this->label1->Text = System::DateTime::Now.ToString("T");
I get the same error in the design editor as when it's set to this: this->label1->Text = (System::DateTime::Now.ToString("T"));
I should also mention, that as long as the code editor doesn't have a problem, when I run the compiled .EXE it works just fine. But I'm leary of ignoring an error in the design editor since this is kinda of my first C++ project.
|
|
|
|
|
Hi,
1.
as long as there are compiler errors, you are not running your new code.
you are either running a previous version (the last EXE that got build successfully), or not at all.
which it is depends on some option (see menu Tools/Options/Projects and Solutions/Build and Run/On Run, when errors occur...; I suggest "Do not launch").
2.
this->label1->Text=DateTime::Now.ToString("T");
works fine for me.
|
|
|
|
|
Okay, so this is what I tried just now...
1. Make a brand new Windows Forms Application project (in Visual Studio 2008 Professional Edition).
2. Place a Label control on the empty form.
3. Select View | Code.
4. Change the line that reads "this->label1->Text = L"label1";" to "this->label1->Text = DateTime::Now.ToString("T");"
5. Select Build | Build Solution.
6. The code editor says the build succeeded.
7. I click the "Form1.h" tab to switch to the design editor, and it says "C++ CodeDOM parser error:Line:70,Column:47 --- Internal Error".
So am I doing something wrong, or missing something?
|
|
|
|
|
Your code is correct, but you should not modify "by hand" the code inside the InitializeComponent method. You should put your custom initialization code inside the constructor, after the call to InitializeComponent() .
|
|
|
|
|
Wohoo! That did it. Thanks!
|
|
|
|
|
Hello, I need to know how to chagne text color.
for example, I declar a text variable
System::Object^ text; how do I change the color of variable text.
thanks.
|
|
|
|
|
i think you should get a book or start from http://msdn.microsoft.com/en-us/library/w0x726c2.aspx[^]
because you are missing the basics
...anyway in one form you can add this code:
System::Windows::Forms::Label ^my_label=gcnew System::Windows::Forms::Label();
my_label->ForeColor=System::Drawing::Color::FromArgb(255,0,0);
my_label->Location = System::Drawing::Point(0, 0);
my_label->Text = "my personal text";
and then add the object to some control object like form's one
this->Controls->Add(this->my_label);
|
|
|
|
|
jashimu wrote: System::Object^ text; how do I change the color of variable text.
You don't. A System::Object does not have a colour attribute, and if it did it would still not be much use. Text formatting is applied when the text is displayed on an output device such as a screen or printer. I also wonder why you are declaring a text item as a System::Object , I'm sure there is a more appropriate class to use.
txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
Sorry, wrong Forum, please delete this Thread
Hallo,
I upgraded from Visual Studio 2005 to Visual Studio 2008, and converted my Project from from VS2005 to VS2008.
But now I get an Error in the following lines:
LOGFONT lFont;
NONCLIENTMETRICS ncm;
ncm.cbSize = sizeof(NONCLIENTMETRICS);
VERIFY(SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
sizeof(NONCLIENTMETRICS), &ncm, 0));
lFont = ncm.lfMessageFont;
SystemParametersInfo() returns false, and there are the following Values in ncm after executing the SystemParametersInfo() Function:
When I open my Project in Windows 7, it works without problem. In XP I get an access exeption in msvcr90d.dll when I ignore the failed execution of SystemParametersInfo.
Can someone help me?
Thank you!
|
|
|
|
|
Are you generating a manifest file?
|
|
|
|
|
Hello,
I'm using VC++.I have a TextBox, and want to convert its String^ value to a char[512] array ???
I thank CodeProject...
|
|
|
|
|
use the search function of the forum....this has been discussed so much times...
hint: look for System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi then it'll be easy
|
|
|
|
|
Use MSDN[^] for simple questions; you even get the title: How to convert from System::String* to Char* in Visual C++. I'm sure you can work out the extra steps needed for yourself. txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
Basically i have 2 class (extended_1_GrObject and extended_2_GrObject) that derive from a general abstract class(basicGrObject):
public ref class basicGrObject abstract
{
public:
basicGrObject(){}
virtual void calculate() abstract;
protected:
~basicGrObject(){}
};
public ref class extended_1_GrObject : public basicGrObject
{
public:
extended_1_GrObject()
{
}
virtual void calculate() override
{
}
protected:
~extended_1_GrObject()
{
}
};
public ref class extended_2_GrObject : public basicGrObject
{
public:
extended_2_GrObject()
{
}
virtual void calculate() override
{
}
protected:
~extended_2_GrObject()
{
}
};
In my code i create a list of this object and foreach element i have to call the calculate method
System::Collections::ArrayList ^my_list=gcnew System::Collections::ArrayList();
extended_1_GrObject ^extended_cl_1=gcnew extended_1_GrObject();
my_list->Add(extended_cl_1);
extended_2_GrObject ^extended_cl_2=gcnew extended_2_GrObject();
my_list->Add(extended_cl_2);
for (int i=0;i<my_list->Count;i++) {
if (my_list[i]->GetType()->Name=="extended_1_GrObject" ) {
extended_1_GrObject ^tmp=static_cast<extended_1_GrObject^>(my_list[i]);
tmp->calculate();
}
else if (my_list[i]->GetType()->Name=="extended_2_GrObject" ) {
extended_2_GrObject ^tmp=static_cast<extended_2_GrObject^>(my_list[i]);
tmp->calculate();
}
}
i really don't like to do the ' my_list[i]->GetType()->Name=="extended_1_GrObject" '
is there some way to avoid that problem, my real class have list of 10000 elements and 10000 string comparison are very very heavymodified on Thursday, March 18, 2010 7:29 AM
|
|
|
|
|
This should work for you (note: psuedo code).
extended_1_GrObject ^extended_cl_1=gcnew extended_1_GrObject();
my_list->Add(extended_cl_1);
extended_2_GrObject ^extended_cl_2=gcnew extended_2_GrObject();
my_list->Add(extended_cl_2);
for (int i=0;i<my_list->Count;i++) {
basicGrObject ^tmp = static_cast<basicGrObject^>(my_list[i]);
tmp->calculate();
} Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
Sometimes looking for something simple is the best way...thank you
|
|
|
|
|
Hi,
I want to convert CString array to managed code ot send it to C#.
For normal CString i did like this,
CString menu = "MENU";
String ^ msg = gcnew String(menu);
Globals1::gwtoolbar->Add(msg);
But now i want to send array of string.i dont know how to do for CString array.
When i gave like this it shows error
CString menu[10];
String[] ^ msg = gcnew String(menu);
How can i convert it?Anu
|
|
|
|
|
I think you need to use the managed array ; see the documentation here[^] for some samples.txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
You would have to do something like this:
array<String^>^ managedArray = gcnew array<String^>(5);
CString nativeArray[5];
for (int i = 0; i < 5; i++)
{
managedArray[i] = Convert::ToString(i);
nativeArray[i] = gcnew String(nativeArray[i]);
}
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
gcnew System::String(char *)
|
|
|
|