|
Hi Luc,
Yes, statistics is a Form and textBox1 is a public field of the TextBox^ kind. I have tried this with textBox1 private and accessed through a public property with the same results. If I do statistics->Controls->Add(text_box), a TextBox control appears (where I dont want it) on the form when ShowDialog() is called. But I don't want to add a control, I want to change the text of an existing control. The Form designer in Visual Studio allows me to select TextBox controls from the toolbox and place them on the Form. The default names as they are placed on the Form would be textBox1, textBox2, etc, so these TextBox(es) already exist on the Form (I shouldn,t have to Add() them). All of the docs that I have read simply show changing the TextBox->Text:: property to whatever the text should be. And when I do that you can see (when executing the code one line at a time) the value of the TextBox changes to the text that I want it to be. It just does not appear when the Form is displayed (the TextBox control appears, just with no text in it).
Buck
|
|
|
|
|
Okay, this is the kind of crap that just drives me insane. Once I added the line 'statistics->Controls->Add(TextBox);' and saw that I got a TextBox where I did not want it, then everything began to behave the way I expected to in the first place. In other words, the code snipet in my original posting that would not display the text is NOW DISPLAYING THE TEXT! Lovely, I already have a ghost in my Microsoft machine, what else is new.
Buck
|
|
|
|
|
I can only get this to work using a public field. I can set up a property for TextBox but I haven't figured out how to set up a property for TextBox::Text.
Buck
|
|
|
|
|
Hi Buck,
I can't tell for sure since I have not seen enough of your code, but I am convinced
you have two textboxes where you only need and want one. Hence, the solution is to
get rid of the second one, then make the only one do what you want.
The proper way is through a property, the quick and dirty one is by making the control
public.
I couldn't create correct code for it right away, but it would look like any
other setter property, with a type of String^, where the new value gets assigned
to myTextBox->Text.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
I stand corrected on my initial response. That chunk of code probably does not work. I think it had to do with the intellisense. My initial attempt (which turned out to be correct) was Form->textBox1->Text::set("string"); but when I typed the -> after textBox1 I did not get a list of properties supplied by the intellisense, nothing. This morning I did get a list of properties and everything was fine.
Buck
|
|
|
|
|
Yeah, the intellisense is starting to mess with me. I tried earlier to setup the property by assigning textBox1->Text = new_value, but I received no intellisense list after the ->. Now I do. I am under the impression that if intellisense doesn't "see" the -> association the compiler won't recognize it either. When this happened in VC++ 6.0 I would delete my .ncb file and rebuild the solution to get the intellisense working again. Is there a way to insure that the intellisense mechanism is working properly?
Thanks,
Works great, lasts a long time.
Buck
|
|
|
|
|
Hi Buck,
you would not get Intellisense (nor compilable code) when omitting a
using namespace line that you need to find a class.
other than that I don't know, I program in VS C# Express Edition 2005 and
Intellisense works well for me (in C# the class name turns blue if it has been
recognized, so black class is missing a "using" statement).
Wenever strange things happen during editing/building, I tend to delete the debug
folder (that is both obj and bin) and do a "rebuild all"; if bin contains some special
files my app needs, I have to be more selective of course.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Hi (Luc), I am using Visual Studio 2005 C++/CLI and I am having a problem with a constructor but it looks okay to me. Can anyone tell if this is because I am using a forward declaration?
namespace MySpace {
ref class Class2; // Here is the forward declaration
public ref class Class1 : Form
{
public: Class1(Form form) { Class1 constructor code here }
public: void Print()
{
Class2^ my_class2 = gcnew Class2^(this); // This is causing error
}
}; // end of Class1
public ref class Class2 : PrintDocument
{
public: Class2(Class1^ class_arg){ Class2 constructor code here }
}; // end of Class2
} // end of MySpace namespace
If the single line in the Print() function is remarked out this compiles fine but if it is unremarked out then I get a "no appropriate default constructor" error. I don't see what's wrong with this constructor, does anyone else?
Thanks
Buck
|
|
|
|
|
There's an extra ^ in there
Plus, the compiler won't be able to resolve the parameterized constructor.
Can you do something like this?
namespace MySpace {
public ref class Class1 : Form
{
public: Class1(Form form) { Class1 constructor code here }
public: void Print();
};
public ref class Class2 : PrintDocument
{
public: Class2(Class1^ class_arg){ Class2 constructor code here }
};
inline void Class1::Print()
{
Class2^ my_class2 = gcnew Class2(this);
}
}
Mark
Last modified: 12mins after originally posted --
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Yes, that did allow me to get the code to compile but it started as someone elses code and now I'm just confused as to why this was supposed to help. I just wanted my Print() and PrintPreview() to have the correct information (size wise) be displayed by PrintPreview() and printed by Print(). I think I'll ditch this whole idea for awhile.
Thanks
Buck
|
|
|
|
|
BuckBrown wrote: but it started as someone elses code and now I'm just confused as to why this was supposed to help
Fun fun!
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi Mark,
It seems I have been providing the fun here, I suggested Buck to look into
my Sokoban article for printing, but then that's in C# and does not know
about circular reference problems...
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
It gets worse when you start using Generics in C++/CLI in this situation!
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Hi George, thanks for the warning. I haven't used generics much yet,
no problems so far...
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
I guess you know how to keep yourself away from big issues; however, I don't. In certain situations, even with formal coding techniques, the compiler will still view your class (with a base clase of Foo ) as a basic ref class with just a base class of Object . The only way I was able to get the code to compile was to create an IFoo generic interface and made <class>Foo a Template class.
Geo
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
That's interesting. There's a bug where the C++/CLI compiler won't recognize that a managed array implements System::Array. The result is you can't pass a managed array to a function that takes an argument as IEnumerable<t>^ or something similar. What you're saying makes it sound like this bug might just be a more specific case of a general problem the C++/CLI compiler has with generics. Unless I'm misunderstanding you.
|
|
|
|
|
iddqd515 wrote: There's a bug where the C++/CLI compiler won't recognize that a managed array implements System::Array. The result is you can't pass a managed array to a function that takes an argument as IEnumerable^ or something similar. What you're saying makes it sound like this bug might just be a more specific case of a general problem the C++/CLI compiler has with generics.
I don't know if what I said applies to that. Nevertheless, translating C# code to C++/CLI may require some extensive hoop jumping. On the other hand, with the help of templates and other C++ idiosyncrasies, you can write code not possible in C#. Since I don't currently have time to write articles, I have been posting in my blog on Code Project some C++/CLI code and brief comments. I will be adding some code on this as soon as my wife allows me to. Any, any comments good, bad or indifferent are welcomed.
-- modified at 10:57 Tuesday 21st August, 2007
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
I forgot to read what I posted. I meant a function with an argument of the generic interface IEnumerable<T>^ not IEnumerable^. That's what prompted me to connect your problem with that bug. I'm about to try fiddling with it.
|
|
|
|
|
|
Interesting stuff, but I'm not sure its quite along the lines I'm looking for. Do you have a code example or solution that demonstrates the problem where the compiler doesn't recognize the proper base class of the derived class and just thinks its a System::Object?
|
|
|
|
|
Yes I do. I will try to post it as soon as I get time! Also, the problem you refering to is something like the following where I have to use a safe_cast to get it to work:
using namespace System;
using namespace System::Collections::Generic;
generic <typename T>
void Foo(IEnumerable<T>^ col)
{
for each (T val in col)
{
Console::WriteLine(val);
}
}
int main(array<System::String ^> ^args)
{
array<int>^ arr = {10, 20, 30, 40, 50};
Foo(safe_cast<IEnumerable<int>^>(arr));
return 0;
}
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
yeah that's exactly the problem. Alternatively you could call Foo<int>(arr). The C# compiler properly recognizes that an array is System::Array so it doesn't require that cast. I don't believe there's any way to dynamically get the generic type argument with typeof or GetType(). It seems this would make it quite difficult to use generics dynamically based on user input or something similar.
|
|
|
|
|
Hello,
I would use a global variable in c++ cli
help me
if exist a means to do this give me an exemple
thanks ,
aef
|
|
|
|
|
I'm assuming you need a global managed object.
One way would be to use gcroot
#include <vcclr.h>
...
gcroot<MyManagedClass ^> MyGlobalObject = gcnew MyManagedClass();
...
extern gcroot<MyManagedClass ^> MyGlobalObject; Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
You can also create a global ref class with static methods.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|