Bada IDE 有代码补全和有意义的错误消息吗?

发布于 2024-12-21 06:10:56 字数 975 浏览 1 评论 0原文

我正在尝试将 Bada 应用程序从 1.2 升级到 2.0,但没有 Bada 经验。我已经构建了项目,并且可以在模拟器中运行它,但我收到了大量警告,并且无法单击文本框来获取键盘并在模拟器中输入任何内容。

不幸的是,警告消息对我来说完全神秘,例如

SearchForm::SearchForm(void) :

给出警告消息“此处初始化时”

此处初始化时会发生什么?

另外,所有 TryCatch 语句都显示语法错误,并且我在互联网上找到的任何内容似乎都没有让它满意:

result OnDraw()
{
    result r = E_SUCCESS;

    Canvas* readerCanvas = GetCanvasN();
    TryCatch(E_SUCCESS == GetLastResult(), "Failed to get canvas: %S", GetErrorMessage(r));

     if (readerCanvas)
     {
         Rectangle tempRect(0, 0, GetBounds().width, GetBounds().height);
         Point tempPoint(0, 0);
         r = readerCanvas->Copy(tempPoint, *iDrawingCanvas, tempRect);
         TryCatch(E_SUCCESS == r, "Failed to copy canvas: %S", GetErrorMessage(r));
         delete readerCanvas;
     }

    return r;

    CATCH:
        delete readerCanvas;
        return r;
}

TryCatch 行说“语句无效”,如果我尝试编辑它以匹配我发现的示例语法错误。

这是怎么回事?

I'm trying to upgrade a Bada app from 1.2 to 2.0 with no experience of Bada. I have the project building and can run it in the emulator but I get a load of warnings and I cant click the text boxes to get a keyboard and enter anything in the emulator.

Unfortunately the warning messages are completely cryptic to me, for example

SearchForm::SearchForm(void) :

gives the warning message "when initialized here"

What when initialized here??!!

Also, all the TryCatch statements show syntax error, and nothing I have found on the internet seems to make it happy:

result OnDraw()
{
    result r = E_SUCCESS;

    Canvas* readerCanvas = GetCanvasN();
    TryCatch(E_SUCCESS == GetLastResult(), "Failed to get canvas: %S", GetErrorMessage(r));

     if (readerCanvas)
     {
         Rectangle tempRect(0, 0, GetBounds().width, GetBounds().height);
         Point tempPoint(0, 0);
         r = readerCanvas->Copy(tempPoint, *iDrawingCanvas, tempRect);
         TryCatch(E_SUCCESS == r, "Failed to copy canvas: %S", GetErrorMessage(r));
         delete readerCanvas;
     }

    return r;

    CATCH:
        delete readerCanvas;
        return r;
}

The TryCatch line says "statement has no effect", if I try edit it to match the examples I'v found I get a syntax error.

What's up with this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

许久 2024-12-28 06:10:56

看起来您正试图通过完全断章取义且仅部分引用来超越 IDE 所谓的不良消息。让我来分解一下:

TryCatch

宏定义为

TryCatch(condition, cleanup, message)

当条件评估为 false 时,这将转到 CATCH。您可以这样想宏:

if (!condition)
{
    goto CATCH;
}

例如,您可以这样使用它:

void TryCatchDemo::UseTryCatch(void)
{
    TryCatch(1==2, , "1 is NOT 2");

    AppLog("This should not appear");

    CATCH:
        AppLog("Catch block");
}

现在,您的第二个参数是一个字符串文字,“Failed to get canvas: %S”,毫不奇怪,它不会用作语句时没有效果:

    "does nothing";
    123;              // just like this

因此编译器会很好地警告您您可能有其他想法。另请注意,语句无效不是语法错误。

“当在这里初始化时”

了解你的语言!引用的代码一开始就不是合法的 C++:

  SearchForm::SearchForm(void) :

充其量这是构造函数定义的开头,缺少初始值设定项列表和主体。在 C++ 语言规范中,类成员按照声明的顺序进行初始化,而不是按照它们在初始化列表中出现的顺序进行初始化。一个最小的例子:

struct X
{
     int a, b;
     X() : b(), a() {}
};

这会导致编译器警告:

/tmp/test.cpp|3 col 13| warning: ‘X::b’ will be initialized after [-Wreorder]
/tmp/test.cpp|3 col 10| warning:   ‘int X::a’ [-Wreorder]
/tmp/test.cpp|4 col 6| warning:   when initialized here [-Wreorder]

如您所见,您不仅剪辑了代码,还剪辑了警告!如果您阅读了整个消息和整个代码,修复将非常明显:

struct X
{
     int a, b;
     X() : a(), b() {}
};

奖励:如果您想知道为什么顺序很重要,请考虑当您这样做时会发生什么:

struct X
{
     int a, b;
     X() : b(), a(b) {} // OOPS!
};

希望这会

有所 帮助使用宏

编辑格式化字符串我刚刚注意到这一点:可能不支持在 Try/Catch 宏中使用格式字符串:

每个支持消息参数的宏实际上都支持格式字符串。格式字符串类似于 printf 的格式字符串在支持它的系统上(bada 不支持它)

It seems like you are trying to outdo your IDE's supposed bad messages by quoting them entirely out of context and only partially. Let me break it down:

TryCatch

The macro is defined as

TryCatch(condition, cleanup, message)

When the condition is evaluated to false, this will goto CATCH. You could think of the macro like this:

if (!condition)
{
    goto CATCH;
}

For example, you can use it like this:

void TryCatchDemo::UseTryCatch(void)
{
    TryCatch(1==2, , "1 is NOT 2");

    AppLog("This should not appear");

    CATCH:
        AppLog("Catch block");
}

Now, your second parameter is a string literal, "Failed to get canvas: %S", which unsurprisingly, doesn't have an effect when used as statement:

    "does nothing";
    123;              // just like this

So the compiler is being nice to warn you of the fact that you probably had something else in mind. Note also, that statement has no effect is not a syntax error.

"when initialized here"

Know your language! The code quoted isn't legal C++ to begin with:

  SearchForm::SearchForm(void) :

At best this is the beginning of a constructor definition, with a missing initializer list and body. In the C++ language spec, class members are initialized in the order in which they were declared, not in the order in which they appear in the initializer list. A minimal example:

struct X
{
     int a, b;
     X() : b(), a() {}
};

This results in the compiler warning:

/tmp/test.cpp|3 col 13| warning: ‘X::b’ will be initialized after [-Wreorder]
/tmp/test.cpp|3 col 10| warning:   ‘int X::a’ [-Wreorder]
/tmp/test.cpp|4 col 6| warning:   when initialized here [-Wreorder]

As you can see, you not only clipped the code but also the warnings! If you read the whole message and the whole code, the fix would be pretty obvious:

struct X
{
     int a, b;
     X() : a(), b() {}
};

Bonus: In case you were wondering, why the ordering matters, consider what happens when you do:

struct X
{
     int a, b;
     X() : b(), a(b) {} // OOPS!
};

Hope this helps

Using a Format String with the Macros

Edit I just noted this: it is probably not supported to use format strings inside the Try/Catch macros:

Each of the macros that support a message parameters actually support format strings. A format string is similar to the format string of printf on systems that support it (bada does NOT support it)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文