SetText() Failing
-
- Posts: 625
- Joined: Mon Nov 15, 2021 9:23 pm
SetText() Failing
Got an issue with a call to VoltageLabel.SetText() failing to work when passed a blank string constant, i.e., "". Compiles fine, but doesn't do anything. I can't think of another way to zero out an Editable Text Label. Am I missing something Java-ish, or is there another way to phrase it?
Cyberwerks Heavy Industries -- viewforum.php?f=76
- honki-bobo
- Posts: 310
- Joined: Sat Nov 09, 2019 1:18 pm
Re: SetText() Failing
That's odd. In my Volt Meter module I do exactly that to clear the labels when no jack is connected and it works just fine.
Can you provide a bit more context, e.g. in which method do you call label.SetText(""), when do you call it...
Alternatively you could try using label.SetText(" "), a string with just a space character.
Can you provide a bit more context, e.g. in which method do you call label.SetText(""), when do you call it...
Alternatively you could try using label.SetText(" "), a string with just a space character.
-
- Posts: 625
- Joined: Mon Nov 15, 2021 9:23 pm
Re: SetText() Failing
Basically, I just can't make the values go away. Here's one usage that fails, in the button notifier:
It also fails in the Reset notifier, and a couple of other places where the value can be set to a null string. I'd rather not use a single space as a null, because there are a number of places where I test on that value, and I don't want to use a string that the user might have typed himself. That way lies madness...or at least, a mad user.
Code: Select all
else if(component == clearCaptionsButton) {
for(int iDex = 0; iDex < page1Caption.length; ++iDex) {
page1Caption[iDex].SetText("");
page1Active[iDex] = false;
page1Caption[iDex].SetVisible(false);
page2Caption[iDex].SetText("");
page2Active[iDex] = false;
page2Caption[iDex].SetVisible(false);
clearCaptionsButton.SetValue(0);
}
}
Cyberwerks Heavy Industries -- viewforum.php?f=76
- honki-bobo
- Posts: 310
- Joined: Sat Nov 09, 2019 1:18 pm
Re: SetText() Failing
If you're using this code in Notify() case Button_Changed you have created a loop by calling clearCaptionsButton.SetValue(0), and you're calling this for every label in your page1Caption array. That could be the cause of your problems. Why are you calling clearCaptionsButton.SetValue(0) anyways?
-
- Posts: 625
- Joined: Mon Nov 15, 2021 9:23 pm
Re: SetText() Failing
Because otherwise, it'll be left in the wrong state. I guess maybe I should have made it a regular button, rather than a toggle. I gotta learn to quit recursing, curse it!
Cyberwerks Heavy Industries -- viewforum.php?f=76
- honki-bobo
- Posts: 310
- Joined: Sat Nov 09, 2019 1:18 pm
Re: SetText() Failing
A quick fix would be
That way it only clears the labels when the toggle is engaged and it resets the toggle just once outside of the for-loop without a call to Notify().
Code: Select all
else if(component == clearCaptionsButton && doubleValue > 0.5) {
for(int iDex = 0; iDex < page1Caption.length; ++iDex) {
page1Caption[iDex].SetText("");
page1Active[iDex] = false;
page1Caption[iDex].SetVisible(false);
page2Caption[iDex].SetText("");
page2Active[iDex] = false;
page2Caption[iDex].SetVisible(false);
}
clearCaptionsButton.SetValueNoNotification(0, true);
}
-
- Posts: 625
- Joined: Mon Nov 15, 2021 9:23 pm
Re: SetText() Failing
Thanks, Martin. I just went ahead and changed the button to a non-toggle type and eliminated the offending instruction, and it works like a charm. Amazing how much that single recursion messed up.
Cyberwerks Heavy Industries -- viewforum.php?f=76
-
- Posts: 625
- Joined: Mon Nov 15, 2021 9:23 pm
Re: SetText() Failing
Quick follow-up question, Martin. Why did you test doubleValue against 0.5, rather than just testing for equality with 1.0 (or 1, which is documented as the active button state)? Is there some quirkiness that could cause the reported value to have drifted from it's documented value?
Cyberwerks Heavy Industries -- viewforum.php?f=76
- honki-bobo
- Posts: 310
- Joined: Sat Nov 09, 2019 1:18 pm
Re: SetText() Failing
No particular reason, it's just what I got used to do when programming modules. You can test for doubleValue == 1 and it will work just the same.
Re: SetText() Failing
By the way, I just had trouble with resetting toggle buttons too. I found that it is not possible to reset a toggle button, when it is part of a group (radio buttons). In this case it only works with setting another toggle button of that group.