Discussion:
Best practice deviation for update_recordset and switch statement
(too old to reply)
Adam
2007-09-12 17:50:01 UTC
Permalink
Hello,

I'm getting a strange BP deviation when i use update_recordset in a switch
statement. The BP deviation says i have unreachable code on the break
command for the second case. I can't see where I'm going wrong, but I might
just be losing my mind. Can anyone see what I'm doing wrong here?

----------------------
static DialogButton updateStuff(DialogButton _dialogButton, str _oldValue,
str _newValue)
{
MyCustTable myCustTable;
;
switch(_dialogButton)
{
case DialogButton::YesToAll :
update_recordset myCustTable
setting myValue = _newValue;
break;

case DialogButton::Yes :
update_recordset myCustTable
setting myValue = _newValue
where myCustTable.myValue == _oldValue;
break; // getting BP deviation here for
unreachable code

default :
break;
}

return(_dialogButton);
}
----------------------

Thanks,
Adam
Axel Kühn
2007-09-12 20:24:01 UTC
Permalink
Hi Adam,

strange...hmm. This is not a bp warning. It's a compiler warning.

I played a little bit with your code and it seems that the compiler has some
"problems" with your code (I get the same warnings).
In my opinion your code is right.

Take a workaround (don't use the switch statement) and use some code like
this.

if(_dialogButton == DialogButton::YesToAll)
{
update_recordset myCustTable
setting phone = _newValue;
}
else if(_dialogButton == DialogButton::Yesl)
{
update_recordset myCustTable
setting phone = _newValue
where myCustTable.phone == _oldValue;
}
--
Sincerely yours
Axel Kühn (visit my Dynamics AX blog at: http://blog.ak-home.net)
Post by Adam
Hello,
I'm getting a strange BP deviation when i use update_recordset in a switch
statement. The BP deviation says i have unreachable code on the break
command for the second case. I can't see where I'm going wrong, but I might
just be losing my mind. Can anyone see what I'm doing wrong here?
----------------------
static DialogButton updateStuff(DialogButton _dialogButton, str _oldValue,
str _newValue)
{
MyCustTable myCustTable;
;
switch(_dialogButton)
{
update_recordset myCustTable
setting myValue = _newValue;
break;
update_recordset myCustTable
setting myValue = _newValue
where myCustTable.myValue == _oldValue;
break; // getting BP deviation here for
unreachable code
break;
}
return(_dialogButton);
}
----------------------
Thanks,
Adam
Adam
2007-09-12 22:02:00 UTC
Permalink
Hi Axel,

Thanks for validating the warning for me. I figured I was just doing
something really stupid but couldn't see what it was. Thanks for the
suggestion, I'll go with the if/else for now.

Thanks again,
Adam
Post by Axel Kühn
Hi Adam,
strange...hmm. This is not a bp warning. It's a compiler warning.
I played a little bit with your code and it seems that the compiler has some
"problems" with your code (I get the same warnings).
In my opinion your code is right.
Take a workaround (don't use the switch statement) and use some code like
this.
if(_dialogButton == DialogButton::YesToAll)
{
update_recordset myCustTable
setting phone = _newValue;
}
else if(_dialogButton == DialogButton::Yesl)
{
update_recordset myCustTable
setting phone = _newValue
where myCustTable.phone == _oldValue;
}
--
Sincerely yours
Axel Kühn (visit my Dynamics AX blog at: http://blog.ak-home.net)
Post by Adam
Hello,
I'm getting a strange BP deviation when i use update_recordset in a switch
statement. The BP deviation says i have unreachable code on the break
command for the second case. I can't see where I'm going wrong, but I might
just be losing my mind. Can anyone see what I'm doing wrong here?
----------------------
static DialogButton updateStuff(DialogButton _dialogButton, str _oldValue,
str _newValue)
{
MyCustTable myCustTable;
;
switch(_dialogButton)
{
update_recordset myCustTable
setting myValue = _newValue;
break;
update_recordset myCustTable
setting myValue = _newValue
where myCustTable.myValue == _oldValue;
break; // getting BP deviation here for
unreachable code
break;
}
return(_dialogButton);
}
----------------------
Thanks,
Adam
Loading...