|
i could help u out put if u have an Instant messenger SN that would be easy cuz than u or i dont have to wait for replys
my AIM SN = KilroyWasHere00
|
|
|
|
|
public ref struct PointRef
{
PointRef()
{
runTime = 0;
ampl = 0;
}
PointRef(unsigned long runTime_, unsigned long ampl_)
{
runTime = runTime_;
ampl = ampl_;
}
PointRef(PointRef const % src)
{
runTime = src.runTime;
ampl = src.ampl;
}
unsigned long runTime;
unsigned long ampl;
};
void main()
{
List<PointRef^> errList(numPts);
List<PointRef^> errListCopy(numPts);
for (int idx = 0; idx < numPts; ++idx)
errList.Add(gcnew PointRef(idx, idx));
errListCopy.AddRange(%errList);
if (Object::ReferenceEquals(errList[0], errListCopy[0]))
{
int i = 0; // Never gets here
}
int b = 1; // Set breakpoint here
}
When I get to the breakpoint b=1, I look in the debugger watch window for errList[0] and errListCopy[0]. The addresses for the two are different. When I change the ampl value for either object, the other object changes as well. This acts correctly because the AddRange is copying the references so both lists should be pointing to same objects. My question is why does the ReferenceEquals return false because they refer to the same instance and why do the references have different addresses?
Thanks, Charlie
|
|
|
|
|
ChuckStar wrote:
List<pointref^> errList(numPts);
List<pointref^> errListCopy(numPts);
for (int idx = 0; idx < numPts; ++idx)
errList.Add(gcnew PointRef(idx, idx));
errListCopy.AddRange(%errList);
You have two lists here. They contain the same data because you copied one to the other. At least, I think that's what the last line does, and the % is a typo. Either way, there is nothing here to suggest that they are both the same list, just two lists of the same items.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thanks for your response Christian. You are correct about the lists containing the same data. To be exact, they contain the same instances of the data. That is what the AddRange function says it does. Copy the contents of the list. The contents are references to objects. As I stated, if I change the ampl member of errList[0], errListCopy[0] gets the change too. This shows that they refer to the same instance as the documentation states. The % is not a typo. This is .NET Beta2 code and the errList is on the stack and the AddRange function takes a reference (^).
If you have any other suggestions, I would like to hear them. Thanks.
Charlie
|
|
|
|
|
You've got two lists that contain the same data. It seems to me that referenceequals would return true if you had two copies of the same list class instance, rather than two instances of the list class with the same objects in them.
But I'm guessing.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
try this:
errList[0]->Equals(errListCopy[0]);
ps: i can't compile, but when i use string compare i found that this method work.
|
|
|
|
|
I tried this also with the same result. The problem with this equals is that Object.Equals is a comparison of the references if the object is a reference, but derived classes can change this to a value equality (see the documentation for more details). It is better to use the ReferenceEquals to ensure you are really determining if the references are refering to the same instance of the object. This is very confusing.
The only things I didn't have in my code to make it compile is:
using namespace System::Collections::Generic;
at the top of the file and
int numPts = 100000;
at the top of main.
Actually I just tried this on another machine and it worked. I am using the .NET Beta2 and I may have an older install on the other machine. I will try it again on that machine and let you know.
Thanks, Charlie
|
|
|
|
|
I figured out one problem. That is why the ReferenceEquals is returning false. Somehow, my compile switch got changed to /02 (optimization = Max speed). If I change it to /Od (Disabled), the ReferenceEquals returns true. This seems like a defect in the compiler. I will submit this to Microsoft.
I still don't understand the debugger watch window showing different addresses for the errList[0] and errListCopy[0] references though.
Thanks all for the comments.
Charlie
|
|
|
|
|
Hello Charlie
I tried both Debug and Release builds. It works as expected for me.
Here's my Release build compiler command line :-
/O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /FD /EHa /MD /Yu"stdafx.h" /Fp"Release\Test_Del.pch" /Fo"Release\\" /Fd"Release\vc80.pdb" /W3 /nologo /c /Zi /clr /TP /errorReport:prompt /FU
void main()
{
int numPts = 10;
List< PointRef^ > errList(numPts);
List< PointRef^ > errListCopy(numPts);
for (int idx = 0; idx < numPts; ++idx)
errList.Add(gcnew PointRef(idx, idx));
errListCopy.AddRange(%errList);
if (Object::ReferenceEquals(errList[0], errListCopy[0]))
{
int i = 0;
Console::WriteLine("here");
}
int b = 1;
}
I am using VS.NET Beta 2
Regards,
Nish
|
|
|
|
|
How is that possible? PointRef is a ref struct, errList[0] and errListCopy[0] should get boxed into two different objects, right?
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
S. Senthil Kumar wrote:
How is that possible? PointRef is a ref struct, errList[0] and errListCopy[0] should get boxed into two different objects, right?
Hello Senthil
In C++, a ref struct and a ref class are both reference types. While a value struct and a value class are value types. So, PointRef in the above example is *not* a value type.
|
|
|
|
|
I keep forgetting that there are ref and value prefixes to structs. Thanks for clearing that up.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Oh crap, PointRef ^x = gcnew PointRef itself seems to create a boxed object. Yet another thing I have to remember when I switch between C++/CLI and C#.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
S. Senthil Kumar wrote:
Oh crap, PointRef ^x = gcnew PointRef itself seems to create a boxed object.
No - PointRef is a reference type - there is no boxing involved here.
|
|
|
|
|
Hi all,
I've got a form with a number of picture boxes. I now want to add a small picturebox on top of these main boxes and be able to see the main box through the small box. If I set the background colour to transparent it, as you probably know, will show the main forms background. Is there a way that I can set the parent of the small box to be the main box?
If not how do I go about creating a picturebox that does have true transparency. I presume I can write my own pictureBox class but don't know how and what I would need to override. Does anyone have any idea because I'm dying here guys!!
|
|
|
|
|
Forget the stupid picture box and draw your own image onto the screen.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
So how do I draw a transparent image?
|
|
|
|
|
Use the DrawImage method that takes an ImageAttributes class instance. That class does many things, transparency is one of them.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Ok, I've used drawimage and imageattributes to make my image transparent. Now how do I float this image over a picturebox control (it seems to be painted under the control).
What I'm basically looking for is an image on the form that will change size and position dynamically. I need to be able to set things like cursors when I'm over a certain area of the image. So my idea was to float another image over the top and use this region to set cursors. The only way to use cursors I've found at the moment is by using forms controls (hence the pictureboxes). I've tried using rectangles and regions but I get the same problem as I'm now getting with images - they seem to be hidden under the picture.
I've tried overriding picturebox but can't seem to get it working. In fact anything I try doesn't produce the goods.
|
|
|
|
|
richiemac wrote:
What I'm basically looking for is an image on the form that will change size and position dynamically.
Sounds like you want to write your own control, from the total base class, that draws these images for you. A picture box will not work for this, that's why I said to draw yourself.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Could you please point me towards a good tutorial on this subject as I'm totally new to this stuff. From what I gather I would have to write my own paint events - is that right??
|
|
|
|
|
That's right. If you search this site for user control, you'll get heaps of hits.
This[^] and this[^] look like good places to start.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi all, I've run into some problems with a template I'm trying to do.
First of all I declared a class and its members in a header file.
eg:
class SomeClass
{
public:
SomeClass(void);
~SomeClass(void);
int SomeFunction(int &, int &);
private:
int someVars;
};
and then defined the class and its members in a source file.
This all worked fine, and run as expected.
but because it's for a library I'm writting, I need it to handle multiple datatypes, so naturally I turned the relivent parts into templates.
The problem is, the template only works if the whole class is declared and defined in the header file. If I try to put the definitions into a source file, I get undefined errors popping up everywhere.
Is there a way and could someone explain how I can declare a template in a header file and define it in a source file. It just keeps things somewhat tidy.
Regards
|
|
|
|
|
hello again :P, my modifing is broken. anyway on a final note to defining / declaring template...
in the eg shown above I had added something similar to
template <typename datatype="">
class SomeClass
{
...
}; replaced all the int's with DATATYPE.
in the source file I was messing around and have tried a few things like
template <typename datatype="">
SomeClass<datatype>::SomeClass(void) { }
... etc etc
I've tried other variouis things, but I haven't found a solution, the net hasn't been much help as of yet.
N/B: Not to worry, I have just read they have to be declared and defined in the same file, grrr. well I have to live with what I've got
Freedom doesn't come without a fight.
|
|
|
|
|
I have made it.
So:
Create cpp file and h file. the cpp file will have strange error. Right click on that cpp in solution explorer. Find Precompiled headers under C/C++. Under option "Create/Use Precompiled Header" chose "Not Using Precompiled Headers"
|
|
|
|