OK ... let me give a small program that *should* work. Then you can perhaps figure out how to implement that in your situation.
I have a simple application with only a button. The paintbox is displayed when you click the button.
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ private declarations }
P : TPaintBox;
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
P := TPaintBox.Create(Form1);
P.Top :=10;
P.Left :=10;
P.Height :=50;
P.Width := 100;
P.Parent := Form1;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
p.Canvas.Pen.Color :=clRed;
P.Canvas.Ellipse(10,10,20,20);
end;
end.
Note that I have changed the way you set the color.