### Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

### Author Topic: PolyLine problems  (Read 2662 times)

#### mtanner

• Sr. Member
• Posts: 261
##### PolyLine problems
« on: January 07, 2017, 07:08:02 pm »
I have a simple component, created in code, based on TGraphicControl, also tried TPaintBox.  Just to start, I'm just trying to draw a line around the canvas area, with thickness of the line set by a variable, call it PenWidth. In the Paint routine I set up the Pen, and then have:

var TestPoints:array[0..4] of TPoint;
var XL,XR,YT,TB:integer;

XL:=PenWidth;
XR:=Width-PenWidth;
YT:=PenWidth;
YB:=Height-PenWidth;

TestPoint[0]:=TPoint(XL,YT);
TestPoint[1]:=TPoint(XR,YT);
TestPoint[2]:=TPoint(XR,YB);
TestPoint[3]:=TPoint(XL,YB);
TestPoint[4]:=TPoint(XL,YT);

Canvas.PolyLine(TestPoints);

My problem is that I get a line across the top, and down the left side of the canvas area. However much I try reducing the values of XR and YB (so they are definitely within the canvas area) the lines do not appear.

I think I must be doing something idiotic. This is such a simple problem I just cannot see why it's not working.

#### bytebites

• Sr. Member
• Posts: 367
##### Re: PolyLine problems
« Reply #1 on: January 07, 2017, 08:10:10 pm »
You fill TestPoint-array and paint TestPoints-array.

#### derek.john.evans

• Guest
##### Re: PolyLine problems
« Reply #2 on: January 08, 2017, 05:13:08 am »
Try using moveto/lineto's and see if you get what you want.

#### mtanner

• Sr. Member
• Posts: 261
##### Re: PolyLine problems
« Reply #3 on: January 08, 2017, 09:38:49 am »
Thanks for the comments. I discovered what the problem, or at least the solution, is.

Height and Width of the control seem unreliable. If I use ClientRect.Right and ClientRect.Bottom instead, then I get the results I expect. Though I do not understand why the Height/Width of the control shouldnot work ok.