Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Possible bug? (Read 2067 times)
Mark_Wills
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 27
Joined: Mar 6th, 2006
Possible bug?
Mar 15th, 2006 at 7:48am
Print Post  
Hmmm.... I have a strange problem here...

I am using FlowChart on an MDI child form.

My MDI parent creates a new child form (which holds the FlowChart), then raises a LoadChart event, which my child form traps, it then does a FlowChart1.ClearAll and uses the LoadFromFileMethod to load a chart into the FlowChart control.

This all works fine... HOWEVER....

IF i CLOSE the child form with the little X icon in the top right, my child form raises a FormClosing event, which I trap on the MDI form, and my MDI form sets ITS reference to the child to Nothing... Fine...

However, if I then create a NEW instance of the child form (using the same instance variable), the flowchart object does NOT seem to be created... It breaks on the FlowChart1.ClearAll method, with the following error message:

System.ObjectDisposedException was unhandled
  Message="Cannot access a disposed object.
Object name: 'FlowChart'."
  ObjectName="FlowChart"
  Source="System.Windows.Forms"
  StackTrace:
      at System.Windows.Forms.Control.CreateHandle()

However, I know the flow chart MUST exist, because (from using Debug.Print to check execution order) the Initialise component routine runs first, then the load event fires, then the load method is executed, yet it says FlowChart is disposed...

So, to summarize:

1) Open form:
childForm=New frmCanvas

2) Load chart:
RaiseEvent LoadProject("FileName")

3) Chart opens - no problem

4) Close form
(in FormClosing): RaiseEvent IAmClosing
(in MDI Parent)
Private Sub CanvasClosing Handles frmCanvas.IAmClosing
  childForm=Nothing
End Sub
5) object reference to child form in MDI form set to nothing (see above)
6) create new form instance:
childForm=New frmCanvas
7) Raise load event again:
RaiseEvent LoadProject("FileName")

8) Error: Cannot access a disposed object... What is happening here? Very confused!!!

Regards

Mark.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Possible bug?
Reply #1 - Mar 15th, 2006 at 8:31am
Print Post  
Hi,

Are you sure that the LoadChart event is not handled by the child form that has just been closed ? That might happen if the child form event handler is attached using the "Handles" keyword. Try using AddHandler and RemoveHandler when the child for is opened/closed.

Regards.
Stoyan
  
Back to top
 
IP Logged
 
Mark_Wills
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 27
Joined: Mar 6th, 2006
Re: Possible bug?
Reply #2 - Mar 15th, 2006 at 10:46am
Print Post  
Ah! Yes, excellent! I never thought of that...

That worries me a little, I would have thought that since I explicitly set the instance to Nothing, that it would die immediately... However, it looks like it's kind of in limbo - I can't access the form because I have de-referenced it by setting the instance variable to Nothing, but IT still sees events... Hmmm.... Is this all connected with Microsofts new Garbage Collector thing? You'll have to forgive me, I still am comparing VB.Net to VB6, and although .Net is far more powerful, some things have become more complex.

I will have to find the 'best practice' for destroying object references cleanly... However, I won't ask that question here as it is clearly a .Net issue and nothing to do with FlowChart.Net

Thanks for the reply, Stoyo.

Mark.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Possible bug?
Reply #3 - Mar 15th, 2006 at 11:53am
Print Post  
Not much into VB.NET myself, but I guess while the object is not GC-ed it could still catch events, even if there are not references to it. That's when using the Handles keyword. You could still use it and check the IsDisposed property before calling the FlowChart methods.

Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint