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。
你需要削減代碼,並使它更多的框架不可知論然後這個和解釋什麼是行不通的。標準C++中沒有'connect events'這樣的事情。否則很難回答。 – pmr 2012-03-06 14:12:27
@pmr:那些'TryCatch'用來檢測錯誤。我很抱歉,但這不是非常標準的C++,因爲沒有正確的異常處理。在代碼中用英語表達更好,或者我想。 – John 2012-03-06 14:14:16
我已經瀏覽了您似乎正在使用的任何框架的文檔,並向您展示了我將要做的事情,但就框架而言,這只是在C++方面而言不一定正確。 – pmr 2012-03-06 14:17:30