-
September 2nd, 2011, 07:10 AM
#1
Conditional operator (==) returning false even the condition is true ?
I have created three property pages on propertysheet,and intializing a bool Value on the parent class of the propertysheet .Now, When accessing that Bool value under InitDialog()Second property page it always return TRUE and while comparing that value in the if statement ,Condition returns false. But if the same procedure, when repeated on third property page Everything works fine.
//My code
//CPage is Parent of propertysheet
// BtnState is Bool value initialized on CPage of Propertysheet
BOOL CGs::OnInitDialog()
{
CPropertyPage::OnInitDialog();
CPage * m_pg = ((CPage*)((CGSPropertySheet*)GetParent())->GetParent());
if(m_pg->BtnState == true)
{
m_set.EnableWindow(false);
}
-
September 2nd, 2011, 07:18 AM
#2
Re: Conditional operator (==) returning false even the condition is true ?
replace "if(m_pg->BtnState == true)" with "if(m_pg->BtnState)"; the reason why it doesn't work is that the boolean constant on the rhs is promoted to the integral value used to represent BtnState, that does not necesserely equal BOOL(true).
Last edited by superbonzo; September 2nd, 2011 at 07:22 AM.
-
September 2nd, 2011, 07:21 AM
#3
Re: Conditional operator (==) returning false even the condition is true ?
1) There is no way we can verify your claims. Instead, save the results to a variable and inspect what that value is:
Code:
BOOL value = (m_pg->BtnState == true);
if ( value ) // value is not 0
2) BOOLs are not bools. The former is a Windows constant, the latter is a C++ type. You should be comparing a BOOL value to TRUE, not true. If you did this, then you wouldn't have run into the issue that superbonzo mentioned. No promotion rules would have occurred, and you would be comparing apples to apples.
3) Use code tags when posting code.
Regards,
Paul McKenzie
-
September 2nd, 2011, 08:29 AM
#4
Re: Conditional operator (==) returning false even the condition is true ?
Thanks Paul and Supermonzo for reply....i am still confuse not getting result...guide me more !!
-
September 2nd, 2011, 08:33 AM
#5
Re: Conditional operator (==) returning false even the condition is true ?
Originally Posted by sunny chouhan
Thanks Paul and Supermonzo for reply....i am still confuse not getting result...guide me more !!
What's your current code?
-
September 2nd, 2011, 08:53 AM
#6
Re: Conditional operator (==) returning false even the condition is true ?
Refer above for the code.......
-
September 2nd, 2011, 09:04 AM
#7
Re: Conditional operator (==) returning false even the condition is true ?
Originally Posted by sunny chouhan
Refer above for the code.......
So you haven't changed it to incorporate the suggestions so far? Why not?
-
September 2nd, 2011, 09:21 AM
#8
Re: Conditional operator (==) returning false even the condition is true ?
Originally Posted by sunny chouhan
Refer above for the code.......
You were already told the above code was wrong and why it was wrong.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|