G'Day Folks,
I have 2 minor problems in a program I an writing (project attached).
Firstly, I thought that canvas.polygon() would draw an unfilled polygon if canvas.brush.style = bsclear!?
In my paint procedure I have:
paintbox1.canvas.brush.style := bssolid;
paintbox1.canvas.brush.color := clwhite;
for a := 1 to num_shapes do
drawStar(drawing[a]);
...
paintbox1.canvas.brush.style := bsclear;
paintbox1.canvas.brush.color := clgreen;
temp.p[pt_count] := pos;
if pt_count=1 then
drawRegPoly(temp)
else if pt_count=2 then
drawstar(temp);
drawRegPoly() and drawStar() do some calculations then call canvas.polygon(). But, as you can see I am setting the brush.style to bsclear in the later bit of code. I was expecting that the resulting polygon would look like a polyline (but closed); whereas it draws filled.
Am I doing something wrong, or is this operating as expected!?
Secondly, if I set the Project Optimization to 1 or 2 (Project > Project Options > Compiler Options > Compilation and Linking > Optimization levels), I get a Hint when compiling:
unit1.pas(141,22) Hint: Local variable "pts" of a managed type does not seem to be initialized
unit1.pas(177,22) Hint: Local variable "pts" of a managed type does not seem to be initialized
"pts" in each case is declared as follows:
var pts : array of tpoint;
The lines referenced above refer to the setlength() calls; which are followed in each case with a loop that populates the arrays. The program works fine and "Heaptrc" finds no memory leaks. If the optimization = 3, the hint is not displayed.
Listed below is the code from Linke 141:
setlength(pts,sides);
a_inc := 2 * pi / sides;
for a := 0 to sides-1 do
begin
rads := angle + a*a_inc;
pts[a] := point(p[0].x + round(radius * sin(rads)),
p[0].y - round(radius * cos(rads)));
end;
So, is there a "better" way to initialize a dynamic array!?
cheers
S.