Re: NullReferenceException on Frame creation

Kris Luyten <[email protected]> Sat, 28 Aug 2004 20:24:43 +0200
Newsgroups gmane.comp.lib.wxwindows.wxnet
Message-ID <[email protected]>
Hi, 


On Sat, 28 Aug 2004 14:08:27 +0200, Alexander Olk
<[email protected]> wrote:
> Am Sa, den 28.08.2004 schrieb Kris Luyten um 13:07:
> > Since m_topFrame is created in the constructor of the
> > WxRenderedInstance class (WxRenderedInstance inherits from App), I
> > find this somewhat confusing. This would mean OnInit is called before
> > the constructor in the same class is?
> 
> When you create an instance of wx.App the protected App base constructor
> gets called first. The protected ctor creates a callback to OnInit and
> actually OnInit gets called then. After that, the rest of your new App
> ctor (WxRenderedInstance) gets processed...

thanks again for your reply! I'm trying to make it work, but I'm still
confused. I hope I am not misunderstanding anything here.

Even if I make absolutely sure my top frame is not null in the OnInit
function, the program still ends with the NullReferenceException. This
is how I coded it now (TopFrame is a getter that ensures the frame is
not null). The exception is still thrown by the Frame constructor.

==================
public class WxRenderedInstance : App, IRenderedInstance{
	private Frame m_topFrame;
	private String m_title;

	public WxRenderedInstance(String title)
	{
		m_title = title;
	}

	public Frame TopFrame
	{
		get {	
		    if(m_topFrame==null)
                            //exception is thrown by the
ContainerFrame constructor
				m_topFrame = new ContainerFrame(m_title);
			return m_topFrame; 
		}
	}
	
	public override bool OnInit()
	{
		TopFrame.Show(true);
		return true;
	}

	[STAThread]
	public void ShowIt()
	{
		Run();
	}

}

class ContainerFrame : Frame
{
	public ContainerFrame(string title) :	base(null, -1, title,
wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE )
	{
               //container for UIML widgets
	}
}
==================

When I change the method "ShowIt" as follows everything works (when
ShowIt it is static, kinda like using the Main method)
==========
[STAThread]
public static void ShowIt()
{
    WxRenderedInstance bla = new WxRenderedInstance("bla");
    bla.Run();
}
==========
unfortunately, this is not usable in my application (if you are
wondering how WxRenderedInstance is being used:
http://cvs.sourceforge.net/viewcvs.py/uimldotnet/uiml.net/Uiml/Rendering/WXnet/WxRenderer.cs?view=markup
-> "Render" )

Regards and thanks again for the previous replies,
Kris


-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=5047&alloc_id=10808&op=click