jvr
Joined: 19 Nov 2007 Posts: 10
|
Posted: Thu Feb 07, 2008 11:53 am Post subject: Bug deleting form |
|
|
Hi,
I need to delete the forms to release some GDI handles but there is a problem, an access violation, here a minimal example that generates the error:
Code: |
import dfl.all;
import std.stdio;
// ---------------------------------------------------------------------
class MyControl
{
private:
PictureBox m_picbox;
public:
this(Control parent )
{
writefln("MyControl Constructor");
m_picbox = new PictureBox;
m_picbox.parent = parent;
}
~this()
{
writefln("MyControl Destructor");
m_picbox.dispose();
}
}
// ---------------------------------------------------------------------
class MyForm : Form
{
private:
MyControl m_my_control;
public:
this()
{
writefln("MyForm Constructor");
m_my_control = new MyControl(this);
}
~this()
{
writefln("MyForm Destructor");
// If you uncomment the next line then the problem is solved, why?
// delete m_my_control;
}
}
// ---------------------------------------------------------------------
int main()
{
MyForm my_form = new MyForm;
Application.run(my_form);
delete my_form;
return(0);
}
|
The output is:
MyForm Constructor
MyControl Constructor
MyForm Destructor
MyControl Destructor
Error: Access Violation
And, how can I know the code that produced the access violation?
Thanks, cheers
Javi
P.S. I'm using DMD 1.026 |
|