我正在使用:
class ISearchFuncs :
public Osp::Ui::IActionEventListener
, public Osp::Ui::ITextEventListener
, public Osp::Ui::IScrollPanelEventListener {
public:
virtual result CloseOverlayKeyb() = 0;
virtual result InitiateSearch() = 0;
};
但是当我尝试通过将指针传递给ISearchFuncs
来连接到这些接口时,回调/事件无法运行。然而,使用实际实现它们的类中的那些接口连接没有这样的问题。我可以忍受这一点,但如果我能够解决这个问题的根源,那将是更好的封装。
class Form1 :
public Osp::Ui::Controls::Form
, public ISearchFuncs
// , public Osp::Ui::IActionEventListener// see below
// , Osp::Ui::ITextEventListener//deleted due to ambiguity
{
这就是它的工作方式:
EditField *pSearchEditField = new EditField;
TryCatch(E_SUCCESS == (r = pSearchEditField->Construct(Rectangle(labelRect.x + labelRect.width / 6, labelRect.y, 7 * labelRect.width / 12, 80)
, EDIT_FIELD_STYLE_NORMAL, INPUT_STYLE_OVERLAY, false, 100, GROUP_STYLE_MIDDLE)),, GetErrorMessage(r));
pSearchEditField->AddTextEventListener(*this);
pSearchEditField->AddScrollPanelEventListener(*this);
pSearchEditField->AddActionEventListener(*this);
TryCatch(E_SUCCESS == (r = pSearchEditField->SetOverlayKeypadCommandButton(COMMAND_BUTTON_POSITION_LEFT,
L"Done", SearchPanel::ID_BUTTON_SEARCH_EDITFIELD_DONE)),, "");
TryCatch(E_SUCCESS == (r = pSearchEditField->SetOverlayKeypadCommandButton(COMMAND_BUTTON_POSITION_RIGHT,
L"Cancel", SearchPanel::ID_BUTTON_SEARCH_EDITFIELD_CANCEL)),, "");
__pScrollPanel->AddControl(*pSearchEditField);
而传递到另一个类来执行等效操作时无法在运行时连接事件:
__pSearchPanel->Construct(labelRect, this, __pScrollPanel);
调用:
result SearchPanel::Construct(const Rectangle &rect, ISearchFuncs *pListener, ScrollPanel *pScrollPare) {
result r = E_SUCCESS;
int x1 = rect.width / 6;
int x2 = rect.width * 3 / 4;
int y1 = rect.height / 3;
EditField *pSearchEditField = new EditField;
TryCatch(E_SUCCESS == (r = pSearchEditField->Construct(Rectangle(rect.x + x1, rect.y, x2 - x1, y1)
, EDIT_FIELD_STYLE_NORMAL, INPUT_STYLE_OVERLAY, false, 100, GROUP_STYLE_MIDDLE)),, GetErrorMessage(r));
pSearchEditField->AddTextEventListener(*pListener);
pSearchEditField->AddScrollPanelEventListener(*pListener);
pSearchEditField->AddActionEventListener(*pListener);
TryCatch(E_SUCCESS == (r = pSearchEditField->SetOverlayKeypadCommandButton(COMMAND_BUTTON_POSITION_LEFT,
L"Done", SearchPanel::ID_BUTTON_SEARCH_EDITFIELD_DONE)),, "");
TryCatch(E_SUCCESS == (r = pSearchEditField->SetOverlayKeypadCommandButton(COMMAND_BUTTON_POSITION_RIGHT,
L"Cancel", SearchPanel::ID_BUTTON_SEARCH_EDITFIELD_CANCEL)),, "");
TryCatch(E_SUCCESS == (r = pScrollPare->AddControl(*pSearchEditField)),, "");
很抱歉代码重复,但这让我发疯了。
我试图关注的成语是part of the bada SDK's help。
答案 0 :(得分:0)
似乎是Osp::Ui::IActionEventListener
,
Osp::Ui::ITextEventListener
,和
Osp::Ui::IScrollPanelEventListener
都源于共同点
基础。您需要使用virtual
继承来避免共同基础
类。
class ISearchFuncs :
public virtual Osp::Ui::IActionEventListener
, public virtual Osp::Ui::ITextEventListener
, public virtual Osp::Ui::IScrollPanelEventListener
{
public:
virtual result CloseOverlayKeyb() = 0;
virtual result InitiateSearch() = 0;
};
答案 1 :(得分:-1)
在被迫接受我在问题中概述的黑客之后,由于使用了存根,IIRC的覆盖方法,我得到了一些错误。
我90%肯定这不是导致我的问题的异常的原因,但100%肯定它比pmr的答案更有意义。