Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comparing pointers won't work!

Status
Not open for further replies.

BorlandDave

Programmer
Jun 13, 2005
86
GB
I am comparing two pointers. When debugging they both contain the same address (both 00E2A7DC), but my comparison doesn't return true. Why not?

Code:
Graphics::TBitmap* Image1;
Image1 = new Graphics::TBitmap;

//point 'image1' to first image in 'ImageList1'
ImageList1->GetBitmap(0, Image1);

//add an item to my list box with Image1 as an object
ListBox1->Items->AddObject("test1",Image1);

//perform comparison between the two pointers
if(ListBox1->Items->Objects[0] == Image1){
    //never gets here!
}
 
as an idea - may be you can try to cast pointers to void* before comparison?
 
Thanks for the suggestion, but that didn't work either. I've simplified the code and it still doesn't work. Is this even possible?

Code:
int integer = 1;
int *integerPtr1 = &integer;
int *integerPtr2 = &integer;

if(integerPtr1 == integerPtr2){
    //never gets here either!
}

And it can't get much simpler than that!
 
Why not cast them to long? Then you just compares two long and that should work.

Furthermore i would print out the values to do a manual check and see what the problem is.

Totte
Keep making it perfect and it will end up broken.
 
Right, I've no idea what's going on, but I re-typed what I had in my original post virtually word for word and it's decided to work now.

3 hours of programming and I'm none the wiser.
 
I don't mind that faults appear, I'm getting pissed on the faults that it's just *poof* works! I mean, You don't learn anything from it!

Totte
Keep making it perfect and it will end up broken.
 
I learned long ago not to argue with success. Just be glad it does. ;-)

It might be possible that a control character that won't display was somehow put into the code. When you started over, that character may have been deleted.


James P. Cottingham
-----------------------------------------
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
The thing is when I was single stepping through the code I could see the two values showing up in my watch list as being the same, but it kept returning the comarison as false!

I hate computers sometimes!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top