|
-
Sep 3rd, 2003, 06:31 PM
#1
Class "Terminate Event"
OK...I am going to use VB6 code here...I know, I know...but I don't know .NET off the top of my head just yet.
I have a class clsWoof
VB Code:
Public Class Class1
Protected Overrides Sub Finalize()
MsgBox("Class Terminated")
MyBase.Finalize()
End Sub
End Class
Ok, now I am assuming that Finalize in .NET is the same as Terminate in VB 6...am I correct in this assumption?
Now in my form I have:
VB Code:
Private Sub cmdWoof_Click() 'VB 6 code, but u get the idea
Dim objNew As clsWoof
objNew = New clsWoof
objNew = Nothing
End Sub
OK, now I would expect the msgbox to appear when I click the button...NOT when I close my app down...I don't understand? Am I missing something really simple???
Woka (Just started .NET and is being really thick )
-
Sep 3rd, 2003, 10:26 PM
#2
Lively Member
Hmmm...
Hi,
You are disturbing the Base Class Event. It will fire when the form event trigger.
To solve this, put it into a Sub...
-
Sep 4th, 2003, 02:11 AM
#3
Frenzied Member
You have to bear in mind that in the brave new world of .NET, the lifetime of a class is ended when the garbage collector comes along and scoops it up some time after your program has released all references to it. In a small program this will not occur until you shut your app down.
If you have code that you need to execute on Finalize - like releasing resources etc., then make your class implement the IDisposable interface and call the Dispose method to nuke it.
-
Sep 4th, 2003, 03:18 AM
#4
WOT?!
So that object in the above example wont get destroyed till my app terminates??? Surely that resuklts in a memory leak!...? 
So how would I implement this IDispose jobbie?
Is this such a basic question that I shouldn't be asking it, like how do I change a caption of a label in vb6???
Does anyone know of any good .NET resources for muppets like me?
Woka
-
Sep 4th, 2003, 05:22 AM
#5
Frenzied Member
Don't worry about memory - it is managed for you - that's what managed code means.
Good references for VB.net include the book:-
Professional VB.Net by Wrox Press (ISBN 1-861004-97-4)
and the websites:
GotDotNet and DotNetForums (I am "Merrion" on both of those btw.)
-
Sep 4th, 2003, 05:27 AM
#6
Frenzied Member
To implement IDisposable...
VB Code:
Public Class PrintJob
Implements IDisposable
Public Overridable Overloads Sub Dispose() Implements IDisposable.Dispose
'\\ Do your cleaning up here....
End Sub
End Class
-
Sep 4th, 2003, 10:07 AM
#7
You'd also then call the dispose method instead of setting it to nothing (or you can do both if really want to).
VB Code:
Private Sub cmdWoof_Click()
Dim objNew As New clsWoof
objNew.Dispose()
End Sub
Although if you don't have any resources to clean up then there is really no need to even call dispose or implement IDisposable.
-
Sep 4th, 2003, 10:11 AM
#8
Cheers. Will have a quick play tonight.
.NET scares the **** out of me 
Woka
-
Sep 4th, 2003, 11:16 AM
#9
Frenzied Member
.NET scares the **** out of me
Going from VB6 to VB.Net is like going from a plastic spoon to a swiss army knife. Sure there's a lot of new things to learn but the amount of new stuff you can do totally makes up for it.
-
Sep 5th, 2003, 03:07 AM
#10
Like what?
Anything that would be used to develop in house software?
WOka
-
Sep 5th, 2003, 05:24 AM
#11
Frenzied Member
New stuff that is really useful:
Managed multithreading - like:
VB Code:
Dim ts As New System.Threading.ThreadStart(AddressOf woofProc)
Dim thread As New System.Threading.Thread(ts)
thread.Start
Or all the new graphics stuff in System.Drawing.
Or having a vast number of new events for forms (like nearly all the ones that EventVB provided and some that it omitted)
Or having direct access to the WndProc for any messages you create (no more subclassing as it was)
Or serialization/deserialization of compound classes to-from XML.
-
Sep 5th, 2003, 05:43 AM
#12
Interesting...Hmmmmmmm.
But you still can't have icons in menus Booooooooooo
Woka
-
Sep 5th, 2003, 05:43 AM
#13
Oh, and MDI forms still suck 
Woka
-
Sep 5th, 2003, 07:45 AM
#14
Originally posted by Wokawidget
Interesting...Hmmmmmmm.
But you still can't have icons in menus Booooooooooo
Woka
It isn't realy that hard to make an ownerdrawn menu in .NET, so you can put in the menu whatever you like.
-
Sep 5th, 2003, 09:44 AM
#15
Don't forget about inheritance and reflection, two of my favs. Oh and delegates can come in handy once in a while.
-
Sep 5th, 2003, 10:37 AM
#16
G'm-buh? 
Woka
-
Sep 5th, 2003, 10:50 AM
#17
Originally posted by Wokawidget
G'm-buh? 
Woka
Is that in reference to the MDI Forms, the Icon Menus, or my post?
Inheritance I'm sure you've probably heard about. Reflection is finding out information about your objects at runtime, like what the variable name is or what type of object it is. A few cool things about this is Enums can be transferred back and forth between their numeric value and the string name. It can actually do a ton more than that but that was the first thing I thought was cool. Delegates are like function pointers or a variable that holds a function instead of a value.
-
Sep 5th, 2003, 10:58 AM
#18
- G'mbuh?
- m'buh?
- m-b?
- fl-m?
- j g-m-fl'buh?
Are all the same, they translate to "What? Please explain kind Sir."

Are you trying to scare me away from .NET?! Grrrrrrrrrrrrrrrr
Woka
-
Sep 5th, 2003, 11:31 AM
#19
There is nothing to fear except fear itself
...and some large animals
...and a women on her period
...and maybe a badger with young'ins
...or what about a few people we all know
...and sometimes clowns can be scary
...well anyway there may be things to fear but .NET isn't one of them.
Its just like most things in the industry and sounds more complicted than it is.
Last edited by Edneeis; Jan 16th, 2004 at 12:30 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|