localSettings强制转换异常

时间:2012-08-31 13:48:30

标签: casting windows-runtime c++-cx

我尝试检查设置“锦标赛”是否已设置,如果没有,则将默认值设置为4。 但是,当我运行它时,它崩溃了一个异常:Platform :: InvalidCastException ^

无效演员在哪里?

ApplicationDataCompositeValue^ tournament_composite = safe_cast<ApplicationDataCompositeValue^>(localSettings->Values->Lookup("tournament"));

if (tournament_composite == nullptr)
{
    values->Insert("tournament", dynamic_cast<PropertyValue^>(PropertyValue::CreateInt32(4)));
}
else
{
    int tournament = safe_cast<IPropertyValue^>(tournament_composite->Lookup("tournament"))->GetInt32();
    switch (tournament)
    {
    case 0:
        lb_tournament->SelectedIndex = 4;
        break;
    case 3:
        lb_tournament->SelectedIndex = 0;
        break;
    case 5:
        lb_tournament->SelectedIndex = 1;
        break;
    case 7:
        lb_tournament->SelectedIndex = 2;
        break;
    case 11:
        lb_tournament->SelectedIndex = 3;
        break;
    default:
        lb_tournament->SelectedIndex = 4;
        break;
    }
}

0 个答案:

没有答案