在函数内部时无法识别的对象 [英] Objects not recognized when inside a function

查看:65
本文介绍了在函数内部时无法识别的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我正在编写一个软件应用程序,我希望使用从一个函数(类)传递到另一个函数(类)的值来更新状态条带标签。问题是新功能无法将工具条识别为对象。围绕这个问题有没有呢?

Hello,

I am writing a software application that I want to update the Status Strips Label with a value passed from one function(class) to another. The problem is the new function does not recognize the tool strip as an object. Is there anyway around this issue?

推荐答案

让我看看你有没有想要做的事情:

你有两个类,一个叫Class1和Class2。

Class1包含一个StatusStripLabel。

Class1调用Class2中的一个函数:

Let me see if I've got what you are trying to do:
You have two classes, one called Class1 and the Class2.
Class1 contains a StatusStripLabel.
Class1 calls a function in Class2:
Class2 c2 = new Class2();
c2.Method(666);



从Class2的实例中,您想要更新Class1中的标签。



你不能从Class2中的Class1访问任何东西,除非它是公共的(假设Class2不是从Class1派生的),即使它是的,你需要Class1的实际实例才能确保在显示的实例中获得正确的控件 - 创建一个新的实例将无效。



如果你有为此,您可能应该阅读:在两个表单之间传输信息,第2部分:孩子到父母 [ ^ ] - 它基于在Forms中执行所有操作,但相同的技术适用于所有类。


From the instance of Class2, you want to update the the label in Class1.

You can't access anything from Class1 in Class2 unless it is public (assuming Class2 is not derived from Class1), and even if it was, you would need the actual instance of Class1 to be sure of getting the right control within the displayed instance - creating a new one will not work.

If you have to do this, then it's likely that you should read this: Transferring information between two forms, Part 2: Child to Parent[^] - it's based around doing everything in Forms, but the same technique works for all classes.


这篇关于在函数内部时无法识别的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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