[Gtk-sharp-list] handling NULL arguments

Duncan Mak duncan@ximian.com
12 Jul 2002 00:53:02 +0800


--=-9aJjMvqrLLy5SjwIev0u
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Heya,

I know Rachel was going to be working on handling having NULL as an
argument to a method. As far as I know, this is needed for
ScrolledWindow and also (as I just discovered) RadioButtons.

I'm calling the RadioButton constructor like this:

	RadioButton radio = new RadioButton (new SList (IntPtr.Zero), "some
text");

but, when adding another new RadioButton to the group,

	radio = new RadioButton (radio.Group, "some more text");

this fails. Is it failing because I use the same 'radio' variable
multiple times?

This snippet compiles but doesn't run right now, the error is:

** (<unknown>:4850): WARNING **: Failed to load library libgtksharp.so
(gtksharp)

** (<unknown>:4850): WARNING **: Failed to load library libgtksharp.so
(gtksharp)

** (<unknown>:4850): WARNING **: unhandled exception
System.NullReferenceException: "Object reference not set to an instance
of an object"
in <0x0005a> (runtime) WidgetViewer.Viewer:Main (object,intptr,intptr)


-- 
Duncan Mak <duncan@ximian.com>

--=-9aJjMvqrLLy5SjwIev0u
Content-Disposition: attachment; filename=radio.cs
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; name=radio.cs; charset=ISO-8859-1

using System;

using Gtk;
using GtkSharp;

namespace WidgetViewer {
	public class TestRadioButton
	{
		static Window window =3D null;
		static Window viewer =3D null;
		static RadioButton radio_button =3D null;

		public static void Main ()
		{
			Application.Init ();
			window =3D new Window ("Foo!");
			window.DeleteEvent +=3D new EventHandler (Window_Delete);

			Button b =3D new Button ("Radio Buttons");
			b.Clicked +=3D new EventHandler (b_clicked);

			window.Add (b);

			window.ShowAll ();
			Application.Run ();
		}
	=09
		public static Gtk.Window Create ()
		{
			window =3D new Window ("GtkRadioButton");
			window.DeleteEvent +=3D new EventHandler (Window_Delete);
			window.SetDefaultSize (200, 100);

			VBox box1 =3D new VBox (false, 0);
			window.Add (box1);

			VBox box2 =3D new VBox (false, 10);
			box2.BorderWidth =3D 10;
			box1.PackStart (box2, true, true, 0);

			radio_button =3D new RadioButton (new GLib.SList (IntPtr.Zero), "Button =
1");
			box2.PackStart (radio_button, true, true, 0);

			radio_button =3D new RadioButton (radio_button.Group, "Button 2");
			radio_button.Active =3D true;
			box2.PackStart (radio_button, true, true, 0);

			box1.PackStart (new HSeparator (), false, true, 0);

			box2 =3D new VBox (false, 10);
			box2.BorderWidth =3D 10;
			box1.PackStart (box2, false, true, 0);

			Button button =3D new Button ("_Close");
			button.Clicked +=3D new EventHandler (Close_Button);
			box2.PackStart (button, true, true, 0);
			button.CanDefault =3D true;
			button.GrabDefault ();

			return window;
		}

		static void Window_Delete (object o, EventArgs args)
		{
			SignalArgs sa =3D (SignalArgs) args;
			window.Destroy ();
			sa.RetVal =3D true;
		}

		static void Close_Button (object o, EventArgs args)
		{
			Window_Delete (o, args);
		}

		static void b_clicked (object o, EventArgs args)
		{
			viewer =3D Create ();
			viewer.ShowAll ();
		}
	}
}

--=-9aJjMvqrLLy5SjwIev0u--