Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8832233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:28:55+00:00 2026-06-14T08:28:55+00:00

I am trying to draw a polygon using GDI. This code works: type TPolygon:

  • 0

I am trying to draw a polygon using GDI. This code works:

type
  TPolygon: Array[0..2] of TPoint;

var 
  ACanvas: TGPGraphics;
  MyBrush: TGPLinearGradientBrush;

...

procedure DrawPolygon;
var
  Polygon: TPolygon;
begin
  Polygon[0].X := 1;
  Polygon[0].Y := 5;
  Polygon[1].X := 10;
  Polygon[1].Y := 15;
  Polygon[2].X := 1;
  Polygon[2].Y := 5;

  ACanvas.FillPolygon(MyBrush, PGPPoint(@Polygon), length(Polygon));
end;

...

This code produces a GDI Value Overflow error:

type
  TPolygon: Array of TPoint;

var 
  ACanvas: TGPGraphics;
  MyBrush: TGPLinearGradientBrush;

...

procedure DrawPolygon;
var
  Polygon: TPolygon;
begin
  SetLength(Polygon, 3);

  Polygon[0].X := 1;
  Polygon[0].Y := 5;
  Polygon[1].X := 10;
  Polygon[1].Y := 15;
  Polygon[2].X := 1;
  Polygon[2].Y := 5;

  ACanvas.FillPolygon(MyBrush, PGPPoint(@Polygon), length(Polygon));
end;

...

The only difference is that one point array is dynamic, the other is static. Obviously the underlying memory values are different, but in what way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T08:28:57+00:00Added an answer on June 14, 2026 at 8:28 am

    Your code is invalid. (First, there is no FillPolygon in TCanvas, and second, a polygon need at least three vertices. Also, there are some syntax errors, like a : instead of = at the const declaration.) I’d suggest the sample

    Polygon[0].X := 1;
    Polygon[0].Y := 1;
    Polygon[1].X := 1;
    Polygon[1].Y := 100;
    Polygon[2].X := 100;
    Polygon[2].Y := 1;
    

    which is a nice triangle. Anyhow, while

    Windows.Polygon(Canvas.Handle, Polygon, 3)
    

    works for a static array, you have to do

    Windows.Polygon(Canvas.Handle, Polygon[0], 3)
    

    for a dynamic array. The reason is that a static array is stored ‘in-place’ in memory, that is, directly at @Polygon, just like a number (e.g., cardinal) is stored, or a ShortString, or a record of such simple types. On the contrary, if Polygon is a dynamic array, then it is really a pointer to the actual, variable-length, data (in much the same way a normal variable-length string works). That is, at @Polygon you only have a pointer, a NativeUInt. The actual data starts at this new address, which you can get by writing @Polygon[0].

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to draw a polygon using the python interface to opencv, cv2. I've
I'm trying to draw an open rectangle using a Polygon: int[] xPoints = {1,1,3,3};
I'm trying to draw a polygon using c# and directx All I get is
I am trying to use Canvas.drawLine method to draw a polygon Here's the code
I am trying to draw in a web worker using html5 canvas. The worker
I'm trying to draw custom UI (a path in this case) on top of
I'm trying to draw a polygon with a stroke of 1 pixel. Because the
I'm using TikX with LaTeX to draw a technical diagram. I'm trying to draw
Right now I am trying to draw a polygon in Cocos2d, but I need
I am trying to draw a line using the Graphics 2D but then the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.