简体   繁体   English

在VB6中处理事件:初始化

[英]Handling events in VB6: Initialize

Here is my question. 这是我的问题。 I have VB6 class FirstClass . 我有VB6类FirstClass In SecondClass i create instance of FirstClass : SecondClass我创建FirstClass实例:

WithEvents fClass as FirstClass

...

Set fClass = New FirstClass

Ok. 好。 Also in SecondClass I have an event Initialize - this is some event of FirstClass 's object (as far as i can understand). 同样在SecondClass我有一个事件Initialize这是FirstClass对象的一些事件(据我所知)。 But when I paste breakpoint in this event, it doesn't fire. 但是,当我在此事件中粘贴断点时,它不会触发。 So could you please explain me why I can't go in this event and how the events handling works in VB6 in general. 因此,您能否解释一下为什么我不能参加此事件,以及事件处理通常在VB6中是如何工作的。
Please, ask questions if my English isn't good for understanding my thoughts 请问我的英语是否不利于理解我的想法

Update: 更新:

Here is property from FirstClass: 这是FirstClass的属性:

Private Property Let IRPCAppMode_Application(RHS As Object) 私有属性让IRPCAppMode_Application(RHS作为对象)

Const METHOD_NAME As String = "IRPCAppMode_Application" 'DO NOT TRANSLATE
On Error GoTo ErrorHandler
Set mApp = RHS
Set m_objRPCProject = mApp.Project
Set m_objDataSet = m_objRPCProject.CurrentDataSet

RaiseEvent Initialize

... ...

I know that mApp object sets only in this line of code, that's all. 我知道mApp对象仅在这行代码中设置,仅此而已。 What i can't understand is how Initialize Event rises in SecondClass and how can we set private property outside of class. 我不明白的是,初始化事件在SecondClass中是如何产生的,以及我们如何在类外设置私有属性。 Calling of Initialize in SecondClass: 在SecondClass中调用Initialize:

Private Sub m_objTestMode_Initialize()
    Const METHOD_NAME As String = "m_objTestMode_Initialize" 'DO NOT TRANSLATE
    On Error GoTo ErrorHandler
    Dim lLoop As Long
    Set mRPCProject = m_objTestMode.Project
    SetupAutoSaveTimer
    SSTab1.Tab = 0
    SSTab2.Tab = 0
    Set m_objToolManager = m_objTestMode.mApp.ToolManager
    Set g_objMonDrives = New clsMonDrives
    Set g_objTrendMonDrives = New clsTrendDrives

.... ....

The Initialize event is already there in your class natively, so if you try to create your own it will be ignored. Initialize事件本身已经存在于您的类中,因此,如果您尝试创建自己的事件,它将被忽略。 Just take your code (get rid of all the custom event code) and put it in the existing Initialize event and you will be fine. 只需将您的代码(摆脱所有自定义事件代码)并将其放入现有的Initialize事件中,您就可以了。

The Initialize event gets fired whenever you create a new instance of your class. 每当您创建类的新实例时,都会触发Initialize事件。 So, if you create an instance of FirstClass with SecondClass you need your Initialize event to go in FirstClass. 因此,如果使用SecondClass创建FirstClass的实例,则需要Initialize事件进入FirstClass。 That way it will get fired when you create your instance of FirstClass. 这样,当您创建FirstClass实例时,它将被触发。 So no, SecondClass's Class_Initialize event isn't an event of FirstClass, it's an event of SecondClass. 因此,不,SecondClass的Class_Initialize事件不是FirstClass的事件,而是SecondClass的事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM