全局对象实例重置? [英] Global object instances get reset?

查看:43
本文介绍了全局对象实例重置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


目前,我正在开发一个Access XP数据库应用程序,它在代码中使用两个

全局对象。这两个对象是

控制器类的实例。例如,其中一个管理表单的多个

打开实例(某种窗口管理器)。


这些全局对象是在模块General中创建,通过定义

,例如:


Dim VwMng作为新的KViewManager


现在这些全局对象似乎有点问题:

当我运行应用程序时,随机时间访问崩溃时

代码访问这些全局对象。显然,这些实例有时会被Access重置
,即使我没有处理代码

并且没有明确地重新编译任何内容。 />

我也尝试修改上面的代码...


Dim VwMng为KViewManager


。 ...然后明确地做一个Set VwMng = New KViewManager"在

AutoExec启动功能中。同样的问题:完全随机,

引用似乎变得无效。


似乎我刚刚把Access带到了太远,或者做了些东西过度支付
复杂左右......所以现在我正在努力重做代码,但这个

全局对象问题不断出现 - 例如定义一个实例

模块中的类Collection会导致同样的问题:

有时候集合会消失得无影无踪,导致Access崩溃。


现在我确定这里的人们有更多的经验

比我有:)有解决方法吗?是否可以可靠地拥有

全局对象?或者这是一个很糟糕的做法,我应该深深地感到羞耻地让我感到羞耻:)?


你的帮助将受到高度赞赏..提前致谢!


你真诚的,

Onno Broekmans

Hi all,

Currently, I''m working on an Access XP database app that uses two
global objects in its code. These two objects are instances of
"controller classes". For example, one of them manages the multiple
open instances of a form (some sort of ''window manager'').

These global objects are created in a module "General", by defining
them with e.g.:

Dim VwMng As New KViewManager

Now there seems to be a bit of a problem with these global objects:
when I''m running the application, at random times Access crashes when
the code accesses these global objects. Apparently, the instances are
sometimes reset by Access --- even though I''m not working on the code
and haven''t recompiled anything explicitly.

I also tried modifying the above code with...

Dim VwMng as KViewManager

....and then explicitly doing a "Set VwMng = New KViewManager" in the
AutoExec startup function. Same problem: completely at random, the
references seem to become invalid.

It seems that I''ve just taken Access too far, or made things overly
complicated or so... So now I''m working to rework the code, but this
global objects problem keeps popping up --- e.g. defining an instance
of the class Collection in a module results in the same problem:
sometimes the collection just vanishes into thin air, crashing Access.

Now I''m sure that there are people in here with a lot more experience
than I have :) Is there a workaround? Is it possible to reliably have
global objects? Or is it such a bad practice that I should be deeply
ashamed :) ?

Your help would be highly appreciated.. Thanks in advance!

Yours sincerely,
Onno Broekmans

推荐答案

2月4,6:48 am,onn ... @ gmail.com < onn ... @ gmail.comwrote:
On Feb 4, 6:48 am, "onn...@gmail.com" <onn...@gmail.comwrote:

大家好,


目前,我正在努力Access XP数据库应用程序,在其代码中使用两个

全局对象。这两个对象是

控制器类的实例。例如,其中一个管理表单的多个

打开实例(某种窗口管理器)。


这些全局对象是在模块General中创建,通过定义

,例如:


Dim VwMng作为新的KViewManager


现在这些全局对象似乎有点问题:

当我运行应用程序时,随机时间访问崩溃时

代码访问这些全局对象。显然,这些实例有时会被Access重置
,即使我没有处理代码

并且没有明确地重新编译任何内容。 />

我也尝试修改上面的代码...


Dim VwMng为KViewManager


。 ..然后明确地做一个Set VwMng = New KViewManager"在

AutoExec启动功能中。同样的问题:完全随机,

引用似乎变得无效。


似乎我刚刚把Access带到了太远,或者做了些东西过度支付
复杂左右......所以现在我正在努力重做代码,但这个

全局对象问题不断出现 - 例如定义一个实例

模块中的类Collection会导致同样的问题:

有时候集合会消失得无影无踪,导致Access崩溃。


现在我确定这里的人们有更多的经验

比我有:)有解决方法吗?是否可以可靠地拥有

全局对象?或者这是一个很糟糕的做法,我应该深深地感到羞耻地让我感到羞耻:)?


你的帮助将受到高度赞赏..提前致谢!


你真诚的,


Onno Broekmans
Hi all,

Currently, I''m working on an Access XP database app that uses two
global objects in its code. These two objects are instances of
"controller classes". For example, one of them manages the multiple
open instances of a form (some sort of ''window manager'').

These global objects are created in a module "General", by defining
them with e.g.:

Dim VwMng As New KViewManager

Now there seems to be a bit of a problem with these global objects:
when I''m running the application, at random times Access crashes when
the code accesses these global objects. Apparently, the instances are
sometimes reset by Access --- even though I''m not working on the code
and haven''t recompiled anything explicitly.

I also tried modifying the above code with...

Dim VwMng as KViewManager

...and then explicitly doing a "Set VwMng = New KViewManager" in the
AutoExec startup function. Same problem: completely at random, the
references seem to become invalid.

It seems that I''ve just taken Access too far, or made things overly
complicated or so... So now I''m working to rework the code, but this
global objects problem keeps popping up --- e.g. defining an instance
of the class Collection in a module results in the same problem:
sometimes the collection just vanishes into thin air, crashing Access.

Now I''m sure that there are people in here with a lot more experience
than I have :) Is there a workaround? Is it possible to reliably have
global objects? Or is it such a bad practice that I should be deeply
ashamed :) ?

Your help would be highly appreciated.. Thanks in advance!

Yours sincerely,

Onno Broekmans



我唯一的一次遇到这种情况的时候还有什么不足......

错误处理。

任何时候你得到调试 /结束错误消息中的选项,

代码将不可避免地停止运行并且重置evert。

应用正确的错误处理将提醒您错误并处理

它没有问你该怎么做。从而没有重置项目。

The only times I''ve encountered this is when there is insufficent
error handling.
Any time you get the "Debug" / "End" option in an error message, the
code will inevitably stop running and everthing is reset.
Applying proper error handling will alert you to the error and handle
it without asking you what to do. Thereby not resetting project.


on **** @ gmail。 com 写道:

现在这些全局对象似乎有点问题:

当我''运行应用程序时,随机时间访问崩溃时代码访问这些全局对象。
显然,实例有时会被Access重置
,即使我没有处理代码

并且没有明确地重新编译任何内容。
Now there seems to be a bit of a problem with these global objects:
when I''m running the application, at random times Access crashes when
the code accesses these global objects. Apparently, the instances are
sometimes reset by Access --- even though I''m not working on the code
and haven''t recompiled anything explicitly.



如果存在未处理的错误,则重置全局变量。这不会出现在.MDE

文件中,而是出现在.MDB文件中。


将错误处理添加到适当的过程中。


有些类可以重新实例化,但是如果它跟踪其他资源(如开放表格),它听起来并不像你的课程是候选人那样。


公共m_instanceYourClass as clsYourClass


公共函数returnObjectRef()as clsYourClass


If(m_instanceYourClass Is Nothing)然后

设置m_instanceYourClass = new clsYourClass

结束如果


设置returnObjectRef = m_instanceYourClass

结束函数

航空代码。这样的事情,但这只是治愈症状,而不是疾病;)

-

''-------------- -

''John Mishefske

''---------------

Global variables are reset if there is an unhandled error. This doesn''t occur in .MDE
files but does in .MDB files.

Add error-handling to appropriate procs.

Some classes can be re-instantiated but it doesn''t sound like your class is a candidate if
it tracking other resources like open forms.

Public m_instanceYourClass As clsYourClass

Public Function returnObjectRef() As clsYourClass

If (m_instanceYourClass Is Nothing) Then
Set m_instanceYourClass = new clsYourClass
End If

Set returnObjectRef = m_instanceYourClass
End Function

air code. Something like that but this is just curing the symptoms and not the disease ;)
--
''---------------
''John Mishefske
''---------------


嗨John和storrboy,


感谢您的回复!但是,我担心,整个项目

已经充满了错误处理:)我很确定

没有发生未处理的错误。


我会尝试使用John的代码,但我想我已经尝试了一次,

无济于事。

您诚挚的,

Onno Broekmans

Hi John and storrboy,

Thanks for your replies! I''m afraid, though, that the whole project
has already been filled with error handling :) I''m pretty sure there
are no unhandled errors occurring.

I will try using John''s code, but I think I already tried it once, to
no avail.

Yours sincerely,
Onno Broekmans


这篇关于全局对象实例重置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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