Form/Object unloading question - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Form/Object unloading question

CaVeDoGCaVeDoG Posts: 10Member
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?

[hr]
Win if you can, lose if you must, but always cheat.

Comments

  • GenjuroGenjuro Posts: 913Member
    : 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?
    :
    : [hr]
    : Win if you can, lose if you must, but always cheat.

    The form willl unload them automatically.

  • apsivamapsivam Posts: 11Member
    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

  • GenjuroGenjuro Posts: 913Member
    : 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 ^^;
  • kel1981bkel1981b Posts: 852Member
    [b][red]This message was edited by kel1981b at 2003-8-5 10:0:22[/red][/b][hr]
    : : 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
    [blue]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[/blue]
    resources, anyway the forms are unloaded only if they're not referenced anywhere else.
    [blue] 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 [/blue]
    : Besides, the post was about controls, not forms ^^;
    [blue]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 [/blue]



  • GenjuroGenjuro Posts: 913Member
    : [b][red]This message was edited by kel1981b at 2003-8-5 10:0:22[/red][/b][hr]
    : : : 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
    : [blue]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[/blue]

    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.
    : [blue] 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
    [/blue]

    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 ^^;
    : [blue]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 [/blue]

    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.
  • kel1981bkel1981b Posts: 852Member
    :
    : 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).
    :
    [red] I just tried the following
    [code]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[/code]. Looks like it uloads [/red]
    : : : Besides, the post was about controls, not forms ^^;
    : : [blue]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 [/blue]
    :
    : 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.
    :
    [red]Sounds for me like confusing therminalogy [/red]
  • GenjuroGenjuro Posts: 913Member
    : :
    : : 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).
    : :
    : [red] I just tried the following
    : [code]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[/code]. Looks like it uloads [/red]

    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 ^^;
    : : : [blue]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 [/blue]
    : :
    : : 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.
    : :
    : [red]Sounds for me like confusing therminalogy [/red]
    :

    Sounds that to me too. But anyways, I tried.
Sign In or Register to comment.