Hello everyone,
I have been working on a project with multiple windows in multiple
classes. The basic premise is a sort of 'automotive maintenance'
project, where I have a list of vehicles (Vehicle is a class), and each
vehicle has a list of 'visits' (which are outlined as below):
Visit (inherited class)
OilChange (class, inherits from Visit)
MufflerRepair (class, inherits from Visit)
TransmissionRepair (class, inherits from Visit)
In my main window, I have a treeview (based on a liststore) of the
vehicles. When I activate a particular row (vehicle), it should hide the
main window, and show the vehicle editing window. When the user is done
editing the vehicle's stats, and closes the window (actually, they would
press the save button), the vehicle-stats-window should close and the
main window should be displayed again.
What I am wondering is how I should go about doing this. Should I create
an 'EditVehicle' class, with a static Edit() method? Or should I make it
instantiable, and have to create an instance of the EditVehicle class
before using it?
Right now, I have tried both, but I am getting random crashes from it. I
am using visual studio to develop, but the debugger does not give a line
number when it crashes. The errors I am receiving are also seemingly
random, as I do not get the same one every time, but here they are:
1)
An unhandled exception of type
'System.Runtime.InteropServices.SEHException' occurred in glib-sharp.dll
Additional information: External component has thrown an exception.
2)
An unhandled exception of type 'System.NullReferenceException' occurred
in glib-sharp.dll
Additional information: Object reference not set to an instance of an
object.
3)
An unhandled exception of type 'System.ExecutionEngineException'
occurred in glib-sharp.dll
Here is some code that may help:
When a row has been activated, the main window calls the EditVehicle's
Edit class as such:
Gtk.Window win = new Gtk.Window(...); //this is the main window
Vehicle vehicle = new Vehicle(...); //the vehicle we have selected
...
EditVehicle ev = new EditVehicle();
ev.Edit(win, vehicle); //the actual call to the editing method
Inside the EditVehicle class:
public class EditVehicle
{
private Gtk.Window win;
private Gtk.Window parent;
private Vehicle vehicle;
public void Edit(Gtk.Window p, Vehicle v)
{
vehicle = v;
parent = p;
parent.HideAll();
win = new Gtk.Window ("Editing Vehicle Stats");
win.DestroyEvent += new
DestroyEventHandler(windowDestroy);
win.DeleteEvent += new DeleteEventHandler
(windowDelete);
//setting up the save button, which has the following
line:
saveButton.Clicked += new
EventHandler(saveButtonHandler);
//code cut to be concise
win.ShowAll();
}
public void windowDelete(object o, DeleteEventArgs args)
{
if (doubleCheckExit())
args.RetVal = true;
else
parent.ShowAll();
}
public void windowDestroy(object o, DestroyEventArgs args)
{
if (doubleCheckExit())
args.RetVal = true;
else
parent.ShowAll();
}
public bool doubleCheckExit()
{
//note - Messaging.YesNo just creates a yes/no
message_dialog box that returns a Boolean, and yes, it is a static
method
return Messaging.YesNo(win, "If you close now, your
changes will be lost.\n\nDo you wish to go back and save your changes?\n
- Press \"Yes\" to go back and save\n - Press \"No\" to close
anyway.");
}
public void saveButtonHandler(object o, EventArgs args)
{
//do the actual saving of the record
win.Destroy();
parent.ShowAll();
}
}
Hopefully this is enough for you all to get some sort of idea of what I
am trying to do. Again, if there is a more canon, accepted, standard way
to open up new windows, please let me know.
I really hate to bug the mailing list, but if anybody has experienced
this before, or has any ideas or insight into these difficulties I've
been having, I'd really appreciate any help at all.
Right now I may try to compile gtk-sharp and see if a more recent
version will help.
Thanks in advance,
Matthew