Hi folks
Just a short question about the ComboBox class.
What is the difference between the ItemIndex and the ID.
Thanks for the help!
LukeS
Hi folks
Just a short question about the ComboBox class.
What is the difference between the ItemIndex and the ID.
Thanks for the help!
LukeS
the index is the place of the item in the list, in the range 0 to getNumItems() - 1
the ID is an identifier you specify when you add an item, it can be whatever you want except 0 (0 is returned by getSelectedId() when nothing is selected).
When you write the code for handling a response to an Item selection, itâs better to use the ID so that it doesnât depend on the order in which elements were added to the list.
I wish juce would use -1 for errors and not 0. It would be a lot cleaner in my gui code.
When dealing with IDs, I always think of 0 as being the only number that should be avoided, as you could legitimately have valid negative IDs. How would it help make your code neater?
When dealing with IDs, I always think of 0 as being the only number that should be avoided, as you could legitimately have valid negative IDs. How would it help make your code neater?[/quote]
I usually use ids to map back to the index in an array of the source data. Since you canât use zero, it always means +1 to the index and -1 to the id every time you are using it. I usually forget somewhere.
I usually use 0 for success, and anything else being an error, with the number indicating what error⊠Blame it on my old C days without exception handlingâŠ
Really? Even in this kind of thing:
if ( doSomething() ){
doSomethingElse();
}
Dude. Trippy.
It was usually in the ways of something like this:
errorEnum result;
if(FAILED(result=someFunc()))
switch(result)
{
case SomeFailureType:
//whatever
break;
case AnotherFailureType:
//other things
break;
// so on...
}
Old fashioned âexceptionâ handling, gotta love it. Usually had plenty of macroâs on hand to simplify near all of that code though.
And no, I donât do that anymore (mostly), so donât worryâŠ
EDIT: And yes, for most things I passed back I did it using references
[code]errorEnum result;
int theID=-1;
if(FAILED(result=getID(theID)))
switch(result)
{
case SomeFailureType:
//whatever
break;
case AnotherFailureType:
//other things
break;
// so onâŠ
}
// Where getID was like:
errorEnum getID(int &return0);[/code]
OK, That makes more sense. A little.
Otherwise, itâd be a kick ass obfuscation method.
That was a standard interface in many libraries. DirectX used to do it perfectly (still might through that nasty COM interface now).