Re: showdialog and 'Cannot access a disposed object'
Matthew Wills <[email protected]> Mon, 7 Jan 2008 09:57:07 +1100
| Newsgroups | gmane.comp.windows.devel.dotnet.winforms |
|---|---|
| Message-ID | <OF680D0C39.9F677FF8-ONCA2573C8.007DEF81-CA2573C8.007E158D@nab.com.au> |
Chris,
This probably isn't the best way, but it should point you down the right
track. Note in particular that I am populating the hashtable with the type
rather than an instance of it. Then I am pulling out the type, getting its
constructor and calling it to create the type.
Again, there is probably a better way to do this - but I pulled this
together rather quickly.
Option Strict On
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim x As New Hashtable
Call x.Add("Bob", GetType(Class1))
Dim y As Type = CType(x.Item("Bob"), Type)
Dim z As System.Reflection.ConstructorInfo =
y.GetConstructor(System.Type.EmptyTypes)
Dim parameters As Object() = Nothing
Dim a As Class1 = CType(z.Invoke(parameters), Class1)
MsgBox(TypeName(a))
End Sub
End Class
Public Class Class1
End Class
Seeya
Matthew Wills | Solution Designer | Adviser Tools and Services | Financial
Planning and Third Party | NAB Technology
Phone: 02 9376 4029 | Mobile: 0435 002 520 | Email:
[email protected]
chris Burgess
<cbtechlists@GMAI
L.COM> To
Sent by: [email protected]
Discussion forum cc
for developers
using Windows Subject
Forms to build Re: [DOTNET-WINFORMS] showdialog
apps and 'Cannot access a disposed
and controls object'
<DOTNET-WINFORMS@
DISCUSS.DEVELOP.C
OM>
05/01/2008 03:49
AM
Please respond to
Discussion forum
for developers
using Windows
Forms to build
apps
and controls
<DOTNET-WINFORMS@
DISCUSS.DEVELOP.C
OM>
I think what I really want is to have the report object hold the type
of report form instead of a reference to the actual form object. I
want the button to create a new form each time of the type listed in
the list box/report object, and not reference existing objects.
On Jan 4, 2008 10:53 AM, Peter Ritchie
<[email protected]> wrote:
> On Fri, 4 Jan 2008 09:56:41 -0600, Mike Andrews
> <[email protected]> wrote:
>
> >The issue is that you're creating a new Report via this line:
> >
> >Dim rpt As New BaseReport
> >
> >and then destroying it and in place of it setting an existing one:
> >
> >rpt = DirectCast(Me.Reports.SelectedValue, BaseReport)
> >
> >since the list box contains the references to the report object, and
> you've
> >previously disposed it it will fail to run.
> >You need to refrain from calling the dispose() method until you're done
> with
> >the form in which the listbox resides.
> >You can then dispose all of the reports.
>
> Bingo, the Reports object should be responsible for disposing what it
> aggregates (or the owner of the Reports object if that class doesn't have
> that concept).
National Australia Bank Ltd - ABN 12 004 044 937
This email may contain confidential information. If you are not the intended
recipient, please immediately notify us at [email protected] or by replying to
the sender, and then destroy all copies of this email. Except where this email
indicates otherwise, views expressed in this email are those of the sender and not
of National Australia Bank Ltd. Advice in this email does not take account of your
objectives, financial situation, or needs. It is important for you to consider these
matters and, if the e-mail refers to a product(s), you should read the relevant
Product Disclosure Statement(s)/other disclosure document(s) before making any
decisions. If you do not want email marketing from us in future, forward this email
with "unsubscribe" in the subject line to [email protected] in order to
stop marketing emails from this sender. National Australia Bank Ltd does not
represent that this email is free of errors, viruses or interference.