Results 1 to 10 of 10

Thread: Problems disposing of form

  1. #1

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    Problems disposing of form

    I have a button on form1 which opens form2.

    The functionality of form2 is reliant upon some of Office being installed. Basicall the Document Imaguing tools of Office.

    If these are not present then the InitializeComponent() method of the forms constructor throws an exception :
    Code:
    [System.Runtime.InteropServices.COMException] = {"Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))"}
    I can obviously trap this with a try catch in the constructor but the problem is I cannot dispose of the problem.


    How can I shut this "form2" down and clean up ?
    The Initialise() hasd not completed so I have this half arsed mess.


    Thanks In Advance

    Parksie

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Problems disposing of form

    Can you avoid using the Office functionality in the constructor and defer it to the Load event handler?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    Re: Problems disposing of form

    Unfortunatly not. It's required at design time in VS.

    This sucks big time.

    Parksie

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Problems disposing of form

    Is it reasonable for the user to use your app at all if this functionality is not available? If not then you could attempt to create an object in code in the app's Startup event handler and refuse to continue if it fails.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    Re: Problems disposing of form

    The functionality offered by this form is not required by 90% of users so this problem rarely comes up.

    Parksie

  6. #6
    Hyperactive Member
    Join Date
    Mar 2008
    Location
    Zeist, The Netherlands
    Posts
    266

    Re: Problems disposing of form

    How about testing the availability of the Office Document Imaging Tools in the Load event of your initial form and disabling the button if it is not found?

  7. #7

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    Re: Problems disposing of form

    To be honest Hamish I'm not sure how to do that though it does sound like a reasonable solution.

    Any tips ?

    Parksie

  8. #8
    Hyperactive Member
    Join Date
    Mar 2008
    Location
    Zeist, The Netherlands
    Posts
    266

    Re: Problems disposing of form

    What piece of code throws the error in the constructor of Form2?
    Isn't it possible to try that (just for testing) in the Load event of your initial form, and if it throws the same error you disable the button?

  9. #9
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,110

    Re: Problems disposing of form

    I agree. If you know that an insurmountable problem could arise in a few moments, check to see whether the problem happens before you get backed into a corner. Do whatever you need to do to confirm that the proper components exist, and don't even let the code go to the bad place if the component isn't available.
    My usual boring signature: Nothing

  10. #10
    Member Reva's Avatar
    Join Date
    Sep 2008
    Posts
    60

    Re: Problems disposing of form

    in form1 at button_click events
    use try catch method to look the avaiable office components.
    and give message to the user if the system is under req's and skip the form2.show statement.

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