创建表单对象时出错 [英] Error when create form object

查看:86
本文介绍了创建表单对象时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的窗口应用程序中,我通过创建表单对象来使用另一种形式的表单值.但是在一种表单中,当我创建它的对象时,我得到了错误:" stackoverflowexception未处理".我不知道该如何解决.我使用以下代码:

In my window application i am using one form value in other form through creating form object.But in one form when i create it''s object i get error:"stackoverflowexception was unhandled". I don''t know how to solve this.I use this code:

 AutoID frmautoid = new AutoID();
 ManualID frmmanualid = new ManualID();
 private void btn_auto_Click(object sender, EventArgs e)
{
                    frmmanualid.UserName = txt_name.Text;
                    frmmanualid.Code = txt_code.Text;
                    frmmanualid.Time = txt_time.Text;

                     frmautoid.ShowDialog();
}


创建此AutoID时出现错误,frmautoid = new AutoID();.此表单中还有许多其他表单对象.
任何人都可以解决.


I got error when i create this AutoID frmautoid = new AutoID();.And many other form object here in this form.
Can Any one solve.

推荐答案

如果在构造对象时遇到堆栈溢出错误,则最可能的解释是该对象直接或间接地创建了一个对象.本身的副本.或者它创建的对象之一正在创建自身的副本.

这很容易解决:在调试器中运行您的应用程序,并在发生异常时查看堆栈跟踪窗格-您应该能够反复看到相同的代码.
If you are getting a stack overflow error when you construct an object, the most likely explanation is that the object is directly or indirectly creating a copy of itself. Or that one of the objects it creates is creating a copy of itself.

This is not difficult to sort out: run your app in the debugger, and look at the stack trace pane when the exception occurs - you should be able to see the same code repeatedly.


堆栈溢出异常是整个编程行业中最容易修复的异常之一.这是为什么:1)应用程序永远不会运行于此异常,始终会终止,因此没有机会错过它; 2)因为这通常只是一个原因:无限"递归或相互递归(http://en.wikipedia.org/wiki/Recursion [ http://en.wikipedia.org/wiki/Recursion_%28computer_science%29 [ ^ ].)

如果仍然无法获取,请参见 递归 .

(这是一个"递归笑话",要理解它,您可能需要查看此页面的源HTML.:-))

关于相互递归,您应该 在这里查看 .

方法是这样的:在某些可疑方法的非常开始上设置一个断点,例如AutoID构造函数.运行该应用程序,并在此断点上观察无限"的中断次数.如果这是错误的观点,请尝试另一点.回到最初触发崩溃"的初始事件.很快,您将到达无限"执行次数的地步.每次查看调试窗口调用堆栈".您将看到每个呼叫的来源,尝试找出差异.将断点添加到接到电话的位置.您将遵循一个收敛的过程,这将导致您导致无限"重复的原因.
—SA
The stack overflow exception is one of the easiest to fix in the whole industry of programming. This is why: 1) the application never runs over this exception, always terminated, so there is no chance to miss it, 2) because this is generally only one reason for that: "infinite" recursion or mutual recursion (http://en.wikipedia.org/wiki/Recursion[^], http://en.wikipedia.org/wiki/Recursion_%28computer_science%29[^].)

If you still don''t get it, see Recursion.

(That was a "recursive joke", to understand it, you might need to look at source HTML of this page. :-))

As to the mutual recursion, you should look here.

The method is this: set a break point on the very beginning of some suspicious method, such as AutoID constructor. Run the application and observe "infinite" number of breaks on this break point. If this is a wrong point, try another one. Go back to the initial event which triggered the "crash" in first place. Pretty soon, you will get to the point which is executed "infinite" number of times. Each time look at the debug window "call stack". You will see where each call comes from, try to detect the difference. Add break point to the point where you got the call. You will follow a converging procedure which will lead you to the cause of "infinite" repetition.

—SA


[请不要删除此信息;这是在解决方案4-SA上解释的递归示例.



要了解相互递归的工作原理,请参阅通常的递归如何工作. 单击此处 .

—SA

[Please don''t remove this post; this is the illustration of recursion explained on Solution 4 — SA]



To understand how mutual recursion works, see how the usual recursion works. Click here.

—SA


这篇关于创建表单对象时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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