跨模块调用函数 [英] Calling functions across modules

查看:74
本文介绍了跨模块调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于对话框的MFC应用程序.该对话框上有几个控件,其中一个是CtrlList控件.我有另一个班级正在使用它来进行其他计算.我将把这些计算的结果传递给ListCtrl控件.

在我的CDialog类中,我有一个名为CListAdd的函数.在CListAdd函数中,我激活一个MessageBox以指示我在该函数中.我在窗体上有一个按钮(按钮A),单击该按钮可以通过调用CListAdd函数将数据添加到ListCtrl中.添加的数据在CListAdd函数中,并且不会从其他任何地方传递.当我单击按钮时,MessageBox弹出,表明我在CListAdd函数中.当我关闭MessageBox时,ListCtrl将按预期填充数据.

在我的CDialog类中,我有另一个按钮(按钮B),该按钮在我的另一个类中调用一个函数.我在此函数中还有一个MessageBox,以指示我在该函数中.当我单击按钮B时,将弹出MessageBox指示我正在使用该功能.然后,我的下一行代码将调用CDialog类中的CListAdd函数.弹出消息框,指示我回到了CListAdd函数.但是,当我关闭MessageBox时,ListCtrl不会填充数据.

我不知道怎么了.如果我从CDialog类中调用CListAdd函数,则会填充该控件.但是,如果我从另一个类中调用CListAdd函数,则不会填充ListCtrl.在开始尝试将数据从另一个类传递到CListAdd函数之前,我想获取静态数据以填充ListCtrl.

我缺少什么?

I have a dialog based MFC application. The dialog has a few controls on it one of which is a CtrlList control. I have another class that I am using to do miscellaneous calculations. I am going to pass the results of those calculations into a ListCtrl control.

Within my CDialog class I have a function named CListAdd. Within the CListAdd function I activate a MessageBox to indicate I am in the function. I have a button (button A) on the form that I can click to add data to the ListCtrl by calling the CListAdd function. The data that is added is in the CListAdd function and is not passed in from anywhere else. When I click the button the MessageBox pops up to indicate I am in the CListAdd function. When I dismiss the MessageBox the ListCtrl gets populated with the data as expected.

Within my CDialog class I have another button (button B) that calls a function in my other class. I also have a MessageBox in this function to indicate I am within the function. When I click button B the MessageBox pops up to indicate I am in the function. My next line of code then does a call to the CListAdd function in my CDialog class. The MessageBox pops up indicating I am back in the CListAdd function. However, when I dismisss the MessageBox, the ListCtrl does not get populated with the data.

I can''t figure out what is wrong. If I call the CListAdd function from within the CDialog class the control get populated. But if I call the CListAdd function from within the other class the ListCtrl does not get populated. I wanted to get the static data to populate the ListCtrl before I started trying to pass data from the other class into the CListAdd function.

What am I missing?

推荐答案

您如何从另一个类调用CDialog类函数?
您必须将CDialog对象指针传递给另一个类,以便它可以使用该指针来调用CDialog函数.
How are you calling the CDialog class function from the other class?
You must pass the CDialog object pointer to the other class so that it can use that pointer to call the CDialog function.


这篇关于跨模块调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆