Which wrong with class Initialize and Terminate event?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 7 of 7

Thread: Which wrong with class Initialize and Terminate event?

  1. #1
    Kenny Guest

    Which wrong with class Initialize and Terminate event?


    In my project whem I create object of one class by New, the class Initialize
    event first is triggered, then I don't do anything else and class Terimate
    evet is triggered immeadiately. How can? Thanks in advance!

  2. #2
    Jonathan Wood Guest

    Re: Which wrong with class Initialize and Terminate event?

    Maybe your class object goes out of scope.

    --
    Jonathan Wood
    SoftCircuits Programming
    http://www.softcircuits.com
    "Kenny" <kzhao@calltrol.com> wrote in message
    news:3ad370ad$1@news.devx.com...
    >
    > In my project whem I create object of one class by New, the class

    Initialize
    > event first is triggered, then I don't do anything else and class Terimate
    > evet is triggered immeadiately. How can? Thanks in advance!




  3. #3
    Jonathan Wood Guest

    Re: Which wrong with class Initialize and Terminate event?

    Maybe your class object goes out of scope.

    --
    Jonathan Wood
    SoftCircuits Programming
    http://www.softcircuits.com
    "Kenny" <kzhao@calltrol.com> wrote in message
    news:3ad370ad$1@news.devx.com...
    >
    > In my project whem I create object of one class by New, the class

    Initialize
    > event first is triggered, then I don't do anything else and class Terimate
    > evet is triggered immeadiately. How can? Thanks in advance!




  4. #4
    Craig Clearman Guest

    Re: Which wrong with class Initialize and Terminate event?

    Kenny,

    >In my project whem I create object of one class by New, the class Initialize
    >event first is triggered, then I don't do anything else and class Terimate
    >evet is triggered immeadiately. How can? Thanks in advance!


    Are you sure it's the same instance that is terminating? If you do
    this:

    Set var = New Object
    ....
    Set var = New Object

    You will get an initialize on the second instantiation, followed
    immediately by a termination on the first instantiation.

    Ciao, Craig


  5. #5
    Craig Clearman Guest

    Re: Which wrong with class Initialize and Terminate event?

    Kenny,

    >In my project whem I create object of one class by New, the class Initialize
    >event first is triggered, then I don't do anything else and class Terimate
    >evet is triggered immeadiately. How can? Thanks in advance!


    Are you sure it's the same instance that is terminating? If you do
    this:

    Set var = New Object
    ....
    Set var = New Object

    You will get an initialize on the second instantiation, followed
    immediately by a termination on the first instantiation.

    Ciao, Craig


  6. #6
    mrfelis Guest

    Re: Which wrong with class Initialize and Terminate event?

    Kenny <kzhao@calltrol.com> wrote in message news:3ad370ad$1@news.devx.com...
    >
    > In my project whem I create object of one class by New, the class

    Initialize
    > event first is triggered, then I don't do anything else and class Terimate
    > evet is triggered immeadiately. How can? Thanks in advance!


    In addition to the other two conditions, the following code will cause the
    same sequence of subs to execute:

    Dim oObject as Class1

    On Error Resume Next
    Set oObject = New Class2

    In this code VB creates a Class2 object, which calls Class2_Initialize. When
    Basic tries to assign the object to oObject VB realises , a bit too late,
    that oObject is an object variable for Class1 and raises an error. Because
    there is no reference for the new object, Resume Next pushes the object out
    of scope and Class2_Terminate will be called.


    --
    ~~~
    !ti timda I ,KO
    ..em deppals nocaeB sivaM
    !draH
    ~~
    C'Ya,
    mrfelis@yahoo!com



  7. #7
    mrfelis Guest

    Re: Which wrong with class Initialize and Terminate event?

    Kenny <kzhao@calltrol.com> wrote in message news:3ad370ad$1@news.devx.com...
    >
    > In my project whem I create object of one class by New, the class

    Initialize
    > event first is triggered, then I don't do anything else and class Terimate
    > evet is triggered immeadiately. How can? Thanks in advance!


    In addition to the other two conditions, the following code will cause the
    same sequence of subs to execute:

    Dim oObject as Class1

    On Error Resume Next
    Set oObject = New Class2

    In this code VB creates a Class2 object, which calls Class2_Initialize. When
    Basic tries to assign the object to oObject VB realises , a bit too late,
    that oObject is an object variable for Class1 and raises an error. Because
    there is no reference for the new object, Resume Next pushes the object out
    of scope and Class2_Terminate will be called.


    --
    ~~~
    !ti timda I ,KO
    ..em deppals nocaeB sivaM
    !draH
    ~~
    C'Ya,
    mrfelis@yahoo!com



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center