Visual Basic

Moderators: None (Apply to moderate this forum)
Number of threads: 18011
Number of posts: 55384

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Form/Object unloading question Posted by CaVeDoG on 2 Aug 2003 at 5:09 PM
If I have an object on the form at design time with index 0 and during run time it loads more indices of that object, in Form_Unload, should I have it unload each of those new objects or will unloading the form do automatically?



Win if you can, lose if you must, but always cheat.
Report
Re: Form/Object unloading question Posted by Genjuro on 2 Aug 2003 at 11:54 PM
: If I have an object on the form at design time with index 0 and during run time it loads more indices of that object, in Form_Unload, should I have it unload each of those new objects or will unloading the form do automatically?
:
:

: Win if you can, lose if you must, but always cheat.

The form willl unload them automatically.

Report
Re: Form/Object unloading question Posted by apsivam on 5 Aug 2003 at 6:39 AM
Try this,

Dim frm As Form

For Each frm In Forms

If (Not frm Is Nothing) Then

Unload frm

End If

Next

This will loop into all loaded form in you app and unload them properly. Put this code in a Sub and call this to "End" your app.
Cheers,

--Sivam

Report
Re: Form/Object unloading question Posted by Genjuro on 5 Aug 2003 at 6:42 AM
: Try this,
:
: Dim frm As Form
:
: For Each frm In Forms
:
: If (Not frm Is Nothing) Then
:
: Unload frm
:
: End If
:
: Next
:
: This will loop into all loaded form in you app and unload them properly. Put this code in a Sub and call this to "End" your app.
: Cheers,
:
: --Sivam


Besides calling End would truncate the whole app without freeing its resources, anyway the forms are unloaded only if they're not referenced anywhere else.
Besides, the post was about controls, not forms ^^;
Report
Re: Form/Object unloading question Posted by kel1981b on 5 Aug 2003 at 9:59 AM
This message was edited by kel1981b at 2003-8-5 10:0:22

: : Try this,
: :
: : Dim frm As Form
: :
: : For Each frm In Forms
: :
: : If (Not frm Is Nothing) Then
: :
: : Unload frm
: :
: : End If
: :
: : Next
: :
: : This will loop into all loaded form in you app and unload them properly. Put this code in a Sub and call this to "End" your app.
: : Cheers,
: :
: : --Sivam
:
:
: Besides calling End would truncate the whole app without freeing its
Hey Genjuro, I like most of you answers on this board. Usually they are very useful and clear but this one caused a couple questions for you. Word 'End' is in double quotes so I thing he was talking about ending/finishing/closing of Application not VB statement 'End'. For example, code like that may be placed in cmdExit_Click Event
resources, anyway the forms are unloaded only if they're not referenced anywhere else.
Question. "the forms are unloaded only if they're not referenced anywhere else." What do you mean by that? I use code like apsivam's example a lot and it closes/unloads all forms that are opened when particular application was running. I am asking this question because I do not understand what "referrenced anywhere else" means
: Besides, the post was about controls, not forms ^^;
Actually, post was about 'Objects/Forms' not controls. If he meant by 'object' 'control', form uloading will work. But if he meant 'object' asking about 'object', form unloading, as I know, won't work. I hope you understand what I am talking about



Report
Re: Form/Object unloading question Posted by Genjuro on 5 Aug 2003 at 10:10 AM
: This message was edited by kel1981b at 2003-8-5 10:0:22

: : : Try this,
: : :
: : : Dim frm As Form
: : :
: : : For Each frm In Forms
: : :
: : : If (Not frm Is Nothing) Then
: : :
: : : Unload frm
: : :
: : : End If
: : :
: : : Next
: : :
: : : This will loop into all loaded form in you app and unload them properly. Put this code in a Sub and call this to "End" your app.
: : : Cheers,
: : :
: : : --Sivam
: :
: :
: : Besides calling End would truncate the whole app without freeing its
: Hey Genjuro, I like most of you answers on this board. Usually they are very useful and clear but this one caused a couple questions for you. Word 'End' is in double quotes so I thing he was talking about ending/finishing/closing of Application not VB statement 'End'. For example, code like that may be placed in cmdExit_Click Event

That's okay, but... guess I was fooled by that capital letter *LOL*
Thanks for the compliments, by the way. I try my best.

: resources, anyway the forms are unloaded only if they're not referenced anywhere else.
: Question. "the forms are unloaded only if they're not referenced anywhere else." What do you mean by that? I use code like apsivam's example a lot and it closes/unloads all forms that are opened when particular application was running. I am asking this question because I do not understand what "referrenced anywhere else" means


Dim Frm as Form1
Dim Frm2 as Form1
...
Set Frm = New Form1
Set Frm2 = Frm

One instance of the form, two references to it. Actually I'm not sure whether it's unloaded or not, if I call "Unload Frm". But I guess, since Forms are objects, they follow VB rules for objects (COM reference counting).

: : Besides, the post was about controls, not forms ^^;
: Actually, post was about 'Objects/Forms' not controls. If he meant by 'object' 'control', form uloading will work. But if he meant 'object' asking about 'object', form unloading, as I know, won't work. I hope you understand what I am talking about

Actually, the first post said:
"If I have an object on the form at design time with index 0 and during run time it loads more indices of that object"
So I thought he loaded some instances of some controls.
Report
Re: Form/Object unloading question Posted by kel1981b on 5 Aug 2003 at 10:33 AM
:
: Dim Frm as Form1
: Dim Frm2 as Form1
: ...
: Set Frm = New Form1
: Set Frm2 = Frm
:
: One instance of the form, two references to it. Actually I'm not sure whether it's unloaded or not, if I call "Unload Frm". But I guess, since Forms are objects, they follow VB rules for objects (COM reference counting).
:
I just tried the following
Private Sub Command1_Click()
Dim Frm As Form1
Dim Frm2 As Form1

Set Frm = New Form1
Set Frm2 = Frm

Frm.Show
End Sub

Private Sub Command2_Click()
For Each Frm In Forms
   Unload Frm
Next

End Sub
. Looks like it uloads

: : : Besides, the post was about controls, not forms ^^;
: : Actually, post was about 'Objects/Forms' not controls. If he meant by 'object' 'control', form uloading will work. But if he meant 'object' asking about 'object', form unloading, as I know, won't work. I hope you understand what I am talking about
:
: Actually, the first post said:
: "If I have an object on the form at design time with index 0 and during run time it loads more indices of that object"
: So I thought he loaded some instances of some controls.
:
Sounds for me like confusing therminalogy
Report
Re: Form/Object unloading question Posted by Genjuro on 6 Aug 2003 at 12:34 AM
: :
: : Dim Frm as Form1
: : Dim Frm2 as Form1
: : ...
: : Set Frm = New Form1
: : Set Frm2 = Frm
: :
: : One instance of the form, two references to it. Actually I'm not sure whether it's unloaded or not, if I call "Unload Frm". But I guess, since Forms are objects, they follow VB rules for objects (COM reference counting).
: :
: I just tried the following
:
Private Sub Command1_Click()
: Dim Frm As Form1
: Dim Frm2 As Form1
: 
: Set Frm = New Form1
: Set Frm2 = Frm
: 
: Frm.Show
: End Sub
: 
: Private Sub Command2_Click()
: For Each Frm In Forms
:    Unload Frm
: Next
: 
: End Sub
. Looks like it uloads


It probably does, then. But, that would unload objects too since references fall out of scope.
Nevertheless, it's probably just me messed up: Forms unload when you unload them, and that's all.

: : : : Besides, the post was about controls, not forms ^^;
: : : Actually, post was about 'Objects/Forms' not controls. If he meant by 'object' 'control', form uloading will work. But if he meant 'object' asking about 'object', form unloading, as I know, won't work. I hope you understand what I am talking about
: :
: : Actually, the first post said:
: : "If I have an object on the form at design time with index 0 and during run time it loads more indices of that object"
: : So I thought he loaded some instances of some controls.
: :
: Sounds for me like confusing therminalogy
:

Sounds that to me too. But anyways, I tried.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.