473,320 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Classes and Objects

Hi,
I have a small big problem with classes and objects..

In VB6 I create a new project, DLL ActiveX; I leave the default name
("progetto1" - in italian); then I rename the class module in "cls1"; I
save the class module with name "cls1.cls" and the project file with
name "clsT.vpb"; and then I add these few lines to the class module:

Private Sub Class_Initialize()
Debug.Print "Class_Initialize()"
End Sub

Private Sub Class_Terminate()
Debug.Print "Class_Terminate()"
End Sub

Public Sub ini()
Debug.Print "INI"
End Sub

I set "5 - Multiuse" as Instancing for cls1, save again and run the
project.

VB.NET; I create a new project "windows application" type; I add a
button to the main form; I add as reference that "progetto1" saved
before (its simple since you can add a vpb project without compiling
it!); for the button click event I add the following:

Dim k As Progetto1.cls1

k = New Progetto1.cls1
k.ini()
k = Nothing

Save and run the VB.NET project too.

Now, pressing the button on the form I aspect to see in the "debug
window" of VB6: "Class_Initialize()", then "INI", then
"Class_Terminate()", but that does not happen! Only
"Class_Initialize()" and "INI" are printed, while "Class_Terminate()"
is only printed when I close the form!

Can someone explain me why this happens?

Sorry for my english...

I forgot to say that I use VB.NET 2003...

Grazie,
D.

Oct 19 '06 #1
4 1316
a) this is a .net newgroup, not a vb6 one
b) your problem is caused the "multiuse instancing"

nokia33948 wrote:
Hi,
I have a small big problem with classes and objects..

In VB6 I create a new project, DLL ActiveX; I leave the default name
("progetto1" - in italian); then I rename the class module in "cls1"; I
save the class module with name "cls1.cls" and the project file with
name "clsT.vpb"; and then I add these few lines to the class module:

Private Sub Class_Initialize()
Debug.Print "Class_Initialize()"
End Sub

Private Sub Class_Terminate()
Debug.Print "Class_Terminate()"
End Sub

Public Sub ini()
Debug.Print "INI"
End Sub

I set "5 - Multiuse" as Instancing for cls1, save again and run the
project.

VB.NET; I create a new project "windows application" type; I add a
button to the main form; I add as reference that "progetto1" saved
before (its simple since you can add a vpb project without compiling
it!); for the button click event I add the following:

Dim k As Progetto1.cls1

k = New Progetto1.cls1
k.ini()
k = Nothing

Save and run the VB.NET project too.

Now, pressing the button on the form I aspect to see in the "debug
window" of VB6: "Class_Initialize()", then "INI", then
"Class_Terminate()", but that does not happen! Only
"Class_Initialize()" and "INI" are printed, while "Class_Terminate()"
is only printed when I close the form!

Can someone explain me why this happens?

Sorry for my english...

I forgot to say that I use VB.NET 2003...

Grazie,
D.
Oct 19 '06 #2
Try changing to the following:
Dim k As Progetto1.cls1

k = New Progetto1.cls1
k.ini()
Marshal.ReleaseComObject (k)

HTH,

--
Tom Shelton

Oct 20 '06 #3

Tom Shelton wrote:
Try changing to the following:
Dim k As Progetto1.cls1

k = New Progetto1.cls1
k.ini()
Marshal.ReleaseComObject (k)

HTH,

--
Tom Shelton
Thanks you very much Tom. That solved: both the problema and my
headache!

Rergards,
D.

Oct 20 '06 #4
D.
Of course Marshal.ReleaseComObject may cause other problems & headaches!

Also you may want to consider Marshal.ReleaseComObject in a loop to
ensure that the COM objects are released (for .NET 2.0 I would recommend
Marshal.FinalReleaseComObject).

Taking into account all the potential problems that ReleaseComObject
introduces...

http://blogs.msdn.com/yvesdolc/archi...17/115379.aspx
http://blogs.msdn.com/cbrumme/archiv.../16/51355.aspx
http://samgentile.com/blog/archive/2003/04/17/5797.aspx

http://msdn2.microsoft.com/en-us/lib....interopservic...

http://msdn2.microsoft.com/en-us/lib....interopservic...

For details on when you should & when you shouldn't (call GC.Collect) see
the four web pages on the GC at:

http://www.tsbradley.net/Reading/CLR.aspx

Especially read these two:

http://blogs.msdn.com/ricom/archive/...29/271829.aspx
http://blogs.msdn.com/ricom/archive/.../02/40780.aspx

Note to self: I need to add the above links to my page on the CLR...

--
Hope this helps
Jay B. Harlow
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"nokia33948" <no********@yahoo.itwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
>
Tom Shelton wrote:
>Try changing to the following:
Dim k As Progetto1.cls1

k = New Progetto1.cls1
k.ini()
Marshal.ReleaseComObject (k)

HTH,

--
Tom Shelton

Thanks you very much Tom. That solved: both the problema and my
headache!

Rergards,
D.
Oct 22 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: vrillusions | last post by:
I've been using functions since I first started using php, but I've been hearing more and more about classes, which I never really looked at that much. I understand the whole OO programming...
145
by: David MacQuigg | last post by:
Playing with Prothon today, I am fascinated by the idea of eliminating classes in Python. I'm trying to figure out what fundamental benefit there is to having classes. Is all this complexity...
7
by: Bo Peng | last post by:
Dear Python group: I am planning on an application that involves several complicated C++ classes. Basically, there will be one or two big data objects and some "action" objects that can act on...
6
by: Marco | last post by:
Howdy! Given: public abstract class A { public abstract int A1(int i); private class B { private int B1(int i) { int j;
11
by: Kevin Prichard | last post by:
Hi all, I've recently been following the object-oriented techiques discussed here and have been testing them for use in a web application. There is problem that I'd like to discuss with you...
3
by: Dave | last post by:
Please - anyone that can help. I am getting confusing results while trying to expose a collection from a web service. I have a webservice in which a web method accepts a collection as a...
2
weaknessforcats
by: weaknessforcats | last post by:
Handle Classes Handle classes, also called Envelope or Cheshire Cat classes, are part of the Bridge design pattern. The objective of the Bridge pattern is to separate the abstraction from the...
2
by: stormogulen | last post by:
Hi! I'm having some problems figuring out how to organize the different tiers of an application using a webservice. The bottom layer is the DAL, and some of the objects in the DAL, I would...
6
by: Immortal Nephi | last post by:
First class is the base class. It has two data: m_Base1 and m_Base2. Second class and third class are derived classes and they are derived from first class. m_Base1 and m_Base2 are inherited into...
45
by: =?Utf-8?B?QmV0aA==?= | last post by:
Hello. I'm trying to find another way to share an instance of an object with other classes. I started by passing the instance to the other class's constructor, like this: Friend Class...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.