Jump to content
  • Advertisement
Sign in to follow this  
PyroBlizzard

C++ Button Enable\Disable Issue

This topic is 4932 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ok, im about to pull my hair out over this. I have an event handler, supposed to check if a textbox is empty or not, and enable a button if its not empty. Well, it will enable the button, but it wont disable it. Here is the function
private: System::Void tAddressBox_TextChanged(System::Object *  sender, System::EventArgs *  e)
		 {
			 if (!(tAddressBox->Text == ""))
			 {
				 bPingServer->Enabled = true;
				 return;
			 }
			 bPingServer->Enabled = false;
		 }
Now, I know that the code should be right, unless im missing something incredibly obvious. I have even done breakpoints in the debug, and the debugger shows plain as day
Quote:
tAddressBox->Text "" String*
So, im lost. I dont know what im doing wrong. Some help, please.

Share this post


Link to post
Share on other sites
Advertisement
So I take it that it never even enters the if statement? Or does it enter but the enable just doesn't work?

Also:

It looks like you're using C#, which I've never used. But I know with C/C++ you have to use a function like strcmp (string compare) when comparing the contents of a string. Otherwise, you'd be comparing "" to the address of that string. But that assumes it's a simple char*, so who knows. Just tossing it out there.

Matt Hughson

Share this post


Link to post
Share on other sites
Yeah, unless tAddressBox->Text is a string object (std::string), you need to use strcmp() or equivelant to compare the strings.

Share this post


Link to post
Share on other sites
Quote:
Original post by matthughson
So I take it that it never even enters the if statement? Or does it enter but the enable just doesn't work?

Also:

It looks like you're using C#, which I've never used. But I know with C/C++ you have to use a function like strcmp (string compare) when comparing the contents of a string. Otherwise, you'd be comparing "" to the address of that string. But that assumes it's a simple char*, so who knows.


Bolded for emphisis. == works fine if you're using std::string.

I've not used C#/.NET either, but check if there's an "empty()" member of text or similar. It's possible that [empty()] and [== ""] are not quite the same.

Share this post


Link to post
Share on other sites
Actually, PyroBlizzard is using Managed C++ and the string he's using is the System::String class.

The comparison should be written:

if( !tAddressBox->Text->Equals("") )
{
...
}

EDIT:

Or, as MaulingMonkey suggested, you could just use the string's empty attribute

if( !tAddressBox->Text->Empty )
{
...
}

Share this post


Link to post
Share on other sites
wow, once again, JWalsh saves the day. Thank you all for your help, I really appreciate it. It was in fact a thing of needing an ->Equals section.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!