I've encountered a bug when using implicit ref casting. All of my widget objects inherit from a Base class that then has a implicit cast for each widget type. The findWidget() method returns a reference to a Base object and then is casted to the Label object. If I try to assign the reference to a class property it can't resolve the method call for setText(). Creating a local variable works just fine.
class CobaltTheme
{
private const Widgets::Label @mClock;
CobaltTheme()
{
@mClock = Window.findWidget("Home.Clock");
onTimerCallback @timerCallback = onTimerCallback(this._clockTimer);
createTimer(1, timerCallback);
}
bool _clockTimer()
{
// ERR : No matching signatures to 'Label::setText(string) const'
mClock.setText(timeToString("%I:%M%P"));
// Works fine:
Widgets::Label @Clock = Window.findWidget("Home.Clock");
Clock.setText(timeToString("%I:%M%P"));
return true;
}
}
// The Base to Label reference cast
r = engine->RegisterObjectBehaviour("Base", asBEHAVE_IMPLICIT_REF_CAST, "Label@ f()", asFUNCTION(Base::castToLabel), asCALL_CDECL_OBJLAST); assert( r >= 0 );
r = engine->RegisterObjectMethod("Window", "Widgets::Base@ findWidget(const string &in)", asMETHOD(Window, findWidget), asCALL_THISCALL); assert( r >= 0 );
Thanks