Results 1 to 19 of 19

Thread: [RESOLVED] Create Objects when needed, and delete them as needed ?

  1. #1

    Thread Starter
    Frenzied Member thegreatone's Avatar
    Join Date
    Aug 2003
    Location
    Oslo, Norway. Mhz:4700 x4
    Posts
    1,333

    Resolved [RESOLVED] Create Objects when needed, and delete them as needed ?

    Ok, i have done a search on these forums and found nothing, yet i have seen this question asked before, i must have used the wrong terms... hmmm

    Anyways, i want to know if i can place Controls such as Webbrowsers and such whenever i need them, and remove them totally when i want to, is it possible ? and if so Code plz

    Thanks
    Zeegnahtuer?

  2. #2
    Super Moderator
    Join Date
    Dec 2003
    Posts
    4,787

    Re: Create Objects when needed, and delete them as needed ?

    Quote Originally Posted by thegreatone
    Ok, i have done a search on these forums and found nothing, yet i have seen this question asked before, i must have used the wrong terms... hmmm

    Anyways, i want to know if i can place Controls such as Webbrowsers and such whenever i need them, and remove them totally when i want to, is it possible ? and if so Code plz

    Thanks
    This should help you out,

    http://www.developerkb.com/modules/w...p?articleid=35
    http://www.vbforums.com/showthread.p...ntime+controls

    Pino

  3. #3

    Thread Starter
    Frenzied Member thegreatone's Avatar
    Join Date
    Aug 2003
    Location
    Oslo, Norway. Mhz:4700 x4
    Posts
    1,333

    Re: Create Objects when needed, and delete them as needed ?

    Thanks, i Bookmarked the 1st link as well... it covers creating them brilliantly, BUT, how do i delete objects i placed in design mode ? they need to be deleted...

    Any more help ? And i'll rate ya post if you can
    Zeegnahtuer?

  4. #4
    Super Moderator
    Join Date
    Dec 2003
    Posts
    4,787

    Re: Create Objects when needed, and delete them as needed ?

    Quote Originally Posted by thegreatone
    Thanks, i Bookmarked the 1st link as well... it covers creating them brilliantly, BUT, how do i delete objects i placed in design mode ? they need to be deleted...

    Any more help ? And i'll rate ya post if you can
    You could set the Visible property to false (It explains in that guide above) or take a look at this

    http://www.vbforums.com/showthread.p...bjects+runtime

    Hope it helps

  5. #5

    Thread Starter
    Frenzied Member thegreatone's Avatar
    Join Date
    Aug 2003
    Location
    Oslo, Norway. Mhz:4700 x4
    Posts
    1,333

    Re: Create Objects when needed, and delete them as needed ?

    Quote Originally Posted by Pino
    You could set the Visible property to false (It explains in that guide above) or take a look at this

    http://www.vbforums.com/showthread.p...bjects+runtime

    Hope it helps
    Yea, thats clears quite a bit of stuff up tho... BUT i don't suppose you could code me an example, say

    Removing WEB (which is a WebBrowser)
    I now nothing about the Controls collection so i'm not sure how to use the Remove method :S HELP ?
    Zeegnahtuer?

  6. #6
    Super Moderator
    Join Date
    Dec 2003
    Posts
    4,787

    Re: Create Objects when needed, and delete them as needed ?

    Quote Originally Posted by thegreatone
    Yea, thats clears quite a bit of stuff up tho... BUT i don't suppose you could code me an example, say

    Removing WEB (which is a WebBrowser)
    I now nothing about the Controls collection so i'm not sure how to use the Remove method :S HELP ?
    I've explained as far as my knowledge goes, I'm not 100% sure why you want to create a web-browser on the fly, But anyways as i said above your best bet is just to set its visible property to false

    Pino

  7. #7

    Thread Starter
    Frenzied Member thegreatone's Avatar
    Join Date
    Aug 2003
    Location
    Oslo, Norway. Mhz:4700 x4
    Posts
    1,333

    Re: Create Objects when needed, and delete them as needed ?

    Quote Originally Posted by Pino
    I've explained as far as my knowledge goes, I'm not 100% sure why you want to create a web-browser on the fly, But anyways as i said above your best bet is just to set its visible property to false

    Pino

    Thanks for your help. You've done the forums proud

    I wanted to make and delete webbrowsers on the fly for the purposes of clearing cookies, IE keeps them in memory, so as well as deleting them you need to close the browser, SO, i figured that if i could remoce the browser after or before clearing cookies i can start fresh with a new browser

    Any more comments ?
    PLUS : I RATED YOU
    Zeegnahtuer?

  8. #8
    Super Moderator
    Join Date
    Dec 2003
    Posts
    4,787

    Re: Create Objects when needed, and delete them as needed ?

    Quote Originally Posted by thegreatone
    Thanks for your help. You've done the forums proud

    I wanted to make and delete webbrowsers on the fly for the purposes of clearing cookies, IE keeps them in memory, so as well as deleting them you need to close the browser, SO, i figured that if i could remoce the browser after or before clearing cookies i can start fresh with a new browser

    Any more comments ?
    PLUS : I RATED YOU
    Hmm, I'm not 100% but how often would you be closing the browser? and out of interest why are we deleting cookies?

  9. #9

    Thread Starter
    Frenzied Member thegreatone's Avatar
    Join Date
    Aug 2003
    Location
    Oslo, Norway. Mhz:4700 x4
    Posts
    1,333

    Re: Create Objects when needed, and delete them as needed ?

    Quote Originally Posted by Pino
    Hmm, I'm not 100% but how often would you be closing the browser? and out of interest why are we deleting cookies?

    Closing a browser and opening a new one whenever the end user wants to, usually every minute or so, and the reason i delete the cookies is because my porogram is logging different accounts into a game that sets session cookies, so i need to close the browser and clear the cookies and open a fresh browser

    I hope that clears it all up
    Zeegnahtuer?

  10. #10

    Thread Starter
    Frenzied Member thegreatone's Avatar
    Join Date
    Aug 2003
    Location
    Oslo, Norway. Mhz:4700 x4
    Posts
    1,333

    Re: Create Objects when needed, and delete them as needed ?

    Permission to bump ?
    Permission Granted...

    BUMP, i still need help with the deletion of objects
    Zeegnahtuer?

  11. #11
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Create Objects when needed, and delete them as needed ?

    Firstly apologies for the time taken to respond. Pino did point the thread out to me earlier but I have been somewhat busy.

    What you need to do is find the program ID of the web browser control. Now in the past I have looked in the registry, but you can find it also in the object browser and it will consist of the library name and the control name. In the case of the web browser control this is:

    SHDocVwCtl.WebBrowser

    You can therefore add the control to your for dynamically as follows:

    Set wb_dynamic = FormName.Controls.Add("SHDocVwCtl.WebBrowser", "wb1")

    You'll notice that on using this, the library generates an error and tells you, you are using the wrong program ID. Don't worry this is normal - you need to change it to the program ID that it tells you, which in this case will be:

    Set wb_dynamic = FormName.Controls.Add("Shell.Explorer.2", "wb1")

    This doesn't only apply to the web browser control, the same method can be used to find the program ID and dynamically create any control. Be sure to declare the object WithEvents if you intend on using any of its events.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  12. #12
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Create Objects when needed, and delete them as needed ?

    Quote Originally Posted by thegreatone
    Permission to bump ?
    Permission Granted...

    BUMP, i still need help with the deletion of objects
    To remove the control you use the remove method. This will destroy the control and free its memory. You reference it through the name you gave it in the second argument of the add function:

    FormName.Controls.Remove("wb1")
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  13. #13
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: Create Objects when needed, and delete them as needed ?

    Quote Originally Posted by thegreatone
    Permission to bump ?
    Permission Granted...

    BUMP, i still need help with the deletion of objects
    I assume you are talking about the (0) member of a control array that you created in ther IDE. If that's the case then you can't delete them at runtime and as suggested above all you can do is to set their visible property to False via code.

  14. #14
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: Create Objects when needed, and delete them as needed ?

    Sorry, will try to add this to my tutorial so people won't get more confused. I'll take it as constructive critisism...




    ØØ

  15. #15
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Create Objects when needed, and delete them as needed ?

    Quote Originally Posted by NoteMe
    Sorry, will try to add this to my tutorial so people won't get more confused. I'll take it as constructive critisism...

    ØØ
    Prehaps just add a line about how to use the object browser to discover the program ID, then your article can be applied to any control.

    Good article though
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  16. #16
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: Create Objects when needed, and delete them as needed ?

    Thanks. Good idea. Will try to update it this weekend.


    ØØ

  17. #17

    Thread Starter
    Frenzied Member thegreatone's Avatar
    Join Date
    Aug 2003
    Location
    Oslo, Norway. Mhz:4700 x4
    Posts
    1,333

    Re: Create Objects when needed, and delete them as needed ?

    Quote Originally Posted by MartinLiss
    I assume you are talking about the (0) member of a control array that you created in ther IDE. If that's the case then you can't delete them at runtime and as suggested above all you can do is to set their visible property to False via code.

    No, i mean i have no control arrays at all, i simply have the object placed at Design time that i wish to remove from the Program at certain points,

    Thanks for your patience people
    Zeegnahtuer?

  18. #18
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Create Objects when needed, and delete them as needed ?

    Quote Originally Posted by thegreatone
    No, i mean i have no control arrays at all, i simply have the object placed at Design time that i wish to remove from the Program at certain points,

    Thanks for your patience people
    You cannot destroy an object created at design time. If you want to do that you have to create it at runtime like I described above and also descibed in NoteMe's tutorial.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  19. #19

    Thread Starter
    Frenzied Member thegreatone's Avatar
    Join Date
    Aug 2003
    Location
    Oslo, Norway. Mhz:4700 x4
    Posts
    1,333

    Re: Create Objects when needed, and delete them as needed ?

    Quote Originally Posted by visualAd
    You cannot destroy an object created at design time. If you want to do that you have to create it at runtime like I described above and also descibed in NoteMe's tutorial.

    O yea, just re-noticed your post
    Thanks
    Zeegnahtuer?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width