473,545 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_Initializ e()
Debug.Print "Class_Initiali ze()"
End Sub

Private Sub Class_Terminate ()
Debug.Print "Class_Terminat e()"
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_Initiali ze()", then "INI", then
"Class_Terminat e()", but that does not happen! Only
"Class_Initiali ze()" and "INI" are printed, while "Class_Terminat e()"
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 1319
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_Initializ e()
Debug.Print "Class_Initiali ze()"
End Sub

Private Sub Class_Terminate ()
Debug.Print "Class_Terminat e()"
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_Initiali ze()", then "INI", then
"Class_Terminat e()", but that does not happen! Only
"Class_Initiali ze()" and "INI" are printed, while "Class_Terminat e()"
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.Release ComObject (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.Release ComObject (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.Release ComObject may cause other problems & headaches!

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

Taking into account all the potential problems that ReleaseComObjec t
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********@yah oo.itwrote in message
news:11******** **************@ h48g2000cwc.goo glegroups.com.. .
>
Tom Shelton wrote:
>Try changing to the following:
Dim k As Progetto1.cls1

k = New Progetto1.cls1
k.ini()
Marshal.Release ComObject (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
8723
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 aspect, but are there any advantages to having classes as opposed to just functions? I've heard that the classes are better because they only load the...
145
6191
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 unecessary? Here is an example of a Python class with all three types of methods (instance, static, and class methods). # Example from Ch.23,...
7
2381
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 the data. I would like to use a script language to control the interaction between these c++ objects. I become interested in Python since it can...
6
2072
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
3803
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 experts. I would like to produce Javascript classes that can be "subclassed" with certain behaviors defined at subclass time. There are plenty of...
3
2968
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 parameter and returns an array of datasets. The collection consists of database connection objects. Based on the simple hierarchy below, you can see...
2
35508
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 implementation so the two can vary independently. Handle classes usually contain a pointer to the object implementation. The Handle object is used...
2
3028
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 like to send via a webservice. That is no problem, just reference the DAL from the webservice. Now in the business layer I am calling methods on the...
6
2171
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 two derived classes. Second class has its own m_Base1 and m_Base2 and third class does the same. I am curious. How can second class and third...
45
2976
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 clsData Private m_objSQLClient As clsSQLClient Private m_objUsers As clsUsers
0
7487
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7420
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7778
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
4966
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3476
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3459
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1908
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1033
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
731
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.