Sign in to follow this  
PyroBlizzard

C++ Button Enable\Disable Issue

Recommended Posts

PyroBlizzard    122
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
matthughson    588
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
MaulingMonkey    1730
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
JWalsh    498
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this