I am trying to create an array of circles (using TShape). However, when I run the code I get an Access violation error on the line (52):
points[index] := TShape.Create(Application);
The complete code is below.
Thank you for this very helpful forum!
unit main_form;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls;
type
TPointArray = array of TShape;
{ TForm1 }
TForm1 = class(TForm)
btn_Generate: TButton;
procedure btn_GenerateClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
public
end;
var
Form1: TForm1;
points: TPointArray;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
end;
procedure TForm1.btn_GenerateClick(Sender: TObject);
var
i: integer;
begin
for i := 1 to 20 do
begin
points[i] := TShape.Create(Application);
points[i].Shape := stCircle;
points[i].left := 60 + 30 * i;
points[i].Top := 200;
points[i].width := 10;
points[i].height := 10;
points[i].Brush.Color := clRed;
end;
end;
end.