From: Markus Humm on
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
From: Simon Hart [MVP] on
Looks like you have reversed engineered that code in delphi.

Check if Label1 has been created.
--
Simon Hart
Visual Developer - Device Application Development MVP
http://simonrhart.blogspot.com


"Markus Humm" wrote:

> 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
>
From: Markus Humm on
Simon Hart [MVP] schrieb:
> 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
From: Simon Hart [MVP] on
What about PictureBox1.Image?
--
Simon Hart
Visual Developer - Device Application Development MVP
http://simonrhart.blogspot.com


"Markus Humm" wrote:

> Simon Hart [MVP] schrieb:
> > 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
>