View previous topic :: View next topic |
Author |
Message |
GencoreOperative
Joined: 04 Oct 2009 Posts: 3
|
Posted: Tue Oct 06, 2009 6:40 am Post subject: Access Violation when adding item to Listbox |
|
|
Hello,
I am a beginner to the D language and am interested in writing user interfaces. I am slowly getting to grips with the DFL library but I have run into this Access Violation and have no idea how to debug or investigate the problem.
It occurs when you uncomment the line:
Code: | //listBox4.items.add("Hello World"); |
I compile it with the statement (using the -console flag to see stdout/err):
Code: | \D\dmd\bin\dfl.exe -console FileList.d |
Below is the source for FileList.d
Code: | /*
Generated by Entice Designer
Entice Designer written by Christopher E. Miller
www.dprogramming.com/entice.php
*/
import dfl.all;
class FileList: dfl.form.Form
{
// Do not modify or move this block of variables.
//~Entice Designer variables begin here.
dfl.textbox.TextBox textBox1;
dfl.listbox.ListBox listBox4;
//~Entice Designer variables end here.
this()
{
initializeFileList();
//@ Other FileList initialization code here.
}
private void initializeFileList()
{
// Do not manually modify this function.
//~Entice Designer 0.8.5.02 code begins here.
//~DFL Form
text = "My Form";
clientSize = dfl.all.Size(384, 342);
//~DFL dfl.textbox.TextBox=textBox1
textBox1 = new dfl.textbox.TextBox();
textBox1.name = "textBox1";
textBox1.dock = dfl.all.DockStyle.TOP;
textBox1.enabled = false;
textBox1.bounds = dfl.all.Rect(0, 0, 384, 24);
textBox1.parent = this;
//~DFL dfl.listbox.ListBox=listBox4
listBox4 = new dfl.listbox.ListBox();
listBox4.name = "listBox4";
listBox4.dock = dfl.all.DockStyle.FILL;
listBox4.scrollAlwaysVisible = true;
listBox4.bounds = dfl.all.Rect(0, 24, 384, 316);
listBox4.parent = this;
//~Entice Designer 0.8.5.02 code ends here.
listBox4.itemHeight = 36;
listBox4.drawMode = DrawMode.OWNER_DRAW_FIXED;
listBox4.drawItem ~= delegate(Object sender, DrawItemEventArgs ea) {
ea.drawBackground();
ea.graphics.drawIcon(this.icon, ea.bounds.x + 2, ea.bounds.y + 2);
ea.graphics.drawText(listBox4.items[ea.index].toString(), ea.font, ea.foreColor,
Rect(ea.bounds.x + 36, ea.bounds.y + 10, ea.bounds.width - 36, 13));
ea.drawFocusRectangle();
};
//listBox4.items.add("Hello World");
}
}
int main()
{
int result = 0;
try
{
Application.enableVisualStyles();
//@ Other application initialization code here.
Application.run(new FileList());
}
catch(Object o)
{
msgBox(o.toString(), "Fatal Error", MsgBoxButtons.OK, MsgBoxIcon.ERROR);
result = 1;
}
return result;
} |
Can anyone suggest ways for me to debug this problem further or to learn more about it?
I can compile all the examples provided with DFL 0.9.8 release successfully and have a working DMD 1.030 install.
Any help is greatly appreciated.
Thanks! |
|
Back to top |
|
|
Chris Miller
Joined: 27 Mar 2004 Posts: 514 Location: The Internet
|
Posted: Tue Oct 06, 2009 2:46 pm Post subject: Re: Access Violation when adding item to Listbox |
|
|
It might be your drawItem handler that's crashing, which isn't being called if there's no items to draw.
You can use a debugger, or the old fashioned way by inserting prints or message boxes every few steps. Debugger information: http://prowiki.org/wiki4d/wiki.cgi?DebugEnvironments
Also, it's advised not to add custom code to the initialize function but to add to the constructor instead. |
|
Back to top |
|
|
Chris Miller
Joined: 27 Mar 2004 Posts: 514 Location: The Internet
|
Posted: Tue Oct 06, 2009 2:49 pm Post subject: Re: Access Violation when adding item to Listbox |
|
|
I think this particular problem is specifically addressed in the FAQ section of the DFL page. Look for the part about access violations. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|