我目前有一个包含 4 个项目的列表视图,在其中一个列表视图项目中,我想实现另一个列表视图,我必须做另一个表单管理器吗?或者我该怎么做?另外,如何在另一个类中调用一个类的函数?或者做一个参考(指针)将信息从一个类传递到另一个类?
1 回答
0
不确定我是否 100% 理解这个问题。
简而言之,您需要从一个列表视图指向另一个列表视图。如果您在表单中,则指向列表视图的本地指针可能就足够了。
同样适用于引用类实例:
class Apple() {
private Basket* basket;
public Apple() {
basket = null;
}
public void setBasket(Basket* basket) {
this->basket = basket;
}
public Basket* getBasket() {
return this->basket;
}
}
class Basket() {
private Apple* apple;
public Basket() {
apple = null;
}
public setApple(Apple* apple) {
this->apple = apple;
this->apple->setBasket(this);
}
}
...
Apple* apple = new Apple();
Basket* basket = new Basket()
basket->setApple(apple);
希望它有一点帮助。
好的,我在这里添加更多代码,看看它是否有帮助它没有经过测试,动态编写以显示主体:
形式A.h
class FormA :
public Osp::Ui::Controls::Form,
public Osp::Ui::IItemEventListener
{
// Other stuff including list
protected:
void OnItemStateChanged (const Osp::Ui::Control &source, int index, int itemId, Osp::Ui::ItemStatus status);
}
表格A.cpp
// Other stuff including constructor and list control creation/population
void FormA::OnItemStateChanged (const Osp::Ui::Control &source, int index, int itemId, Osp::Ui::ItemStatus status) {
// Construct and show other form
FormB* b = new FormB(itemId);
// Add to frame and set formb as current
}
表格B.h
class FormA :
public Osp::Ui::Controls::Form,
public Osp::Ui::IItemEventListener
{
private int itemId;
public:
FormA(int itemId);
}
表格B.cpp
FormA::FormA(int itemId) {
this->itemId = itemId;
}
// Now somewhere in your form initialization read the itemId
// value (this->itemId) and decide what you want to show in the form's list view
于 2011-12-07T13:51:19.957 回答