What's wrong with this drawing code?

  • Thread starter Thread starter Markus Humm
  • Start date Start date
M

Markus Humm

Hello,

the following drawing code used inside a BDS2006 for CF application
gives me this stack trace:

Project1.exe
NullReferenceException

Application::Run+0xf
Project1::Project1+0xa

This is the source:

var i,n, z:Integer;
g,g1:System.Drawing.Graphics;
p:System.Drawing.Pen;
t:Integer;
img:System.Drawing.Image;
begin
g:=self.CreateGraphics;
p:=System.Drawing.Pen.Create(System.Drawing.Color.Blue);
z:=0;
for n := 1 to 20 do
begin
for i := 5 to 235 do
begin
g.DrawLine(p, i, 10, i, 270);
inc(z);
Label1.Text:=z.ToString;
end;
Application.DoEvents;
end;
g.Dispose;

PictureBox1.Visible:=true;
p:=System.Drawing.Pen.Create(System.Drawing.Color.Red);

// img:=Bitmap.Create(230,260);

The crash occurs in the course of this, but all functions are (according
to the MS helpfile) supported from CF. I'm using CF 1.0 in the emulator.

g1:=Graphics.FromImage(PictureBox1.Image);
z:=0;
for n := 1 to 20 do
begin
for i := 5 to 235 do
begin
g1.DrawLine(p, i, 10, i, 270);
inc(z);
Label1.Text:=z.ToString;
end;
Application.DoEvents;
end;
// g.Dispose;

So what's wrong with this?
I'm basically trying to replace some direct drawing code with something
which draws into a bitmap first and displays the bitmap then as I feel
this should be faster.

The source above is just a demonstration/test project so the graphic
drawn isn't really usefull.

Greetings

Markus
 
Looks like you have reversed engineered that code in delphi.

Check if Label1 has been created.
 
Simon said:
Looks like you have reversed engineered that code in delphi.

Check if Label1 has been created.

Hello,

label1 is created and works properly in the first part of the code.

Greetings

Markus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top