Board index » delphi » Can't create an array of TPanel

Can't create an array of TPanel

The following code should create a set of panels with a TCheckBox inside.

procedure TfrmMain.FormShow(Sender: TObject);
var
  iCt: Byte;

begin
  for iCt := 0 to 9 do
  begin
    aPnl[iCt] := TPanel.Create(Self);
    aPnl[iCt].Left       := 4;
    aPnl[iCt].Top        := 36 + (37 * iCt);
    aPnl[iCt].Font       := pnlT.Font;
    aPnl[iCt].Width      := pnlT.Width;
    aPnl[iCt].Height     := pnlT.Height;
    aPnl[iCt].BevelInner := pnlT.BevelInner;
    aPnl[iCt].BevelOuter := pnlT.BevelOuter;
    aPnl[iCt].Visible    := True;

    aChk[iCt] := TCheckBox.Create(aPnl[iCt]);
    aChk[iCt].Top     := 4;
    aChk[iCt].Left    := 4;
    aChk[iCt].Checked := False;
  end;
end;

The objects above are declared at the public section of the form as it
follows:

    aPnl:   array[0..9] of TPanel;
    aChk:   array[0..9] of TCheckBox;

    pnlT is a TPanel witch I use as a model for the Panels of the array.

It just doesn't work ! The panels seem to be created, but I can't see them
on the form. Am I forgetting something ? There is another way to create an
array of TPanel with a TCheckBox in it ?

Thanks in advance,

Carlos I. Molina
carlosimol...@hotmail.com

 

Re:Can't create an array of TPanel


Carlos,

You will need to also set the PARENT for each.

Carlos I. Molina <carlosimol...@uol.com.br> wrote in message
news:7qslr9$mii1@forums.borland.com...

Quote
> The following code should create a set of panels with a TCheckBox inside.

> procedure TfrmMain.FormShow(Sender: TObject);
> var
>   iCt: Byte;

> begin
>   for iCt := 0 to 9 do
>   begin
>     aPnl[iCt] := TPanel.Create(Self);
>     aPnl[iCt].Left       := 4;
>     aPnl[iCt].Top        := 36 + (37 * iCt);
>     aPnl[iCt].Font       := pnlT.Font;
>     aPnl[iCt].Width      := pnlT.Width;
>     aPnl[iCt].Height     := pnlT.Height;
>     aPnl[iCt].BevelInner := pnlT.BevelInner;
>     aPnl[iCt].BevelOuter := pnlT.BevelOuter;
>     aPnl[iCt].Visible    := True;

>     aChk[iCt] := TCheckBox.Create(aPnl[iCt]);
>     aChk[iCt].Top     := 4;
>     aChk[iCt].Left    := 4;
>     aChk[iCt].Checked := False;
>   end;
> end;

> The objects above are declared at the public section of the form as it
> follows:

>     aPnl:   array[0..9] of TPanel;
>     aChk:   array[0..9] of TCheckBox;

>     pnlT is a TPanel witch I use as a model for the Panels of the array.

> It just doesn't work ! The panels seem to be created, but I can't see them
> on the form. Am I forgetting something ? There is another way to create an
> array of TPanel with a TCheckBox in it ?

> Thanks in advance,

> Carlos I. Molina
> carlosimol...@hotmail.com

Re:Can't create an array of TPanel


Carlos,

You need to add

    aPnl[iCt].Parent := self

and

aChk[iCt].Parent := aPnl[iCt];

Regards,
Stephan

--
Sleep my friend and you will see,
Dream is my reality

Carlos I. Molina <carlosimol...@uol.com.br> a crit dans le message :
7qslr9$m...@forums.borland.com...

Quote
> The following code should create a set of panels with a TCheckBox inside.

> procedure TfrmMain.FormShow(Sender: TObject);
> var
>   iCt: Byte;

> begin
>   for iCt := 0 to 9 do
>   begin
>     aPnl[iCt] := TPanel.Create(Self);
>     aPnl[iCt].Left       := 4;
>     aPnl[iCt].Top        := 36 + (37 * iCt);
>     aPnl[iCt].Font       := pnlT.Font;
>     aPnl[iCt].Width      := pnlT.Width;
>     aPnl[iCt].Height     := pnlT.Height;
>     aPnl[iCt].BevelInner := pnlT.BevelInner;
>     aPnl[iCt].BevelOuter := pnlT.BevelOuter;
>     aPnl[iCt].Visible    := True;

>     aChk[iCt] := TCheckBox.Create(aPnl[iCt]);
>     aChk[iCt].Top     := 4;
>     aChk[iCt].Left    := 4;
>     aChk[iCt].Checked := False;
>   end;
> end;

> The objects above are declared at the public section of the form as it
> follows:

>     aPnl:   array[0..9] of TPanel;
>     aChk:   array[0..9] of TCheckBox;

>     pnlT is a TPanel witch I use as a model for the Panels of the array.

> It just doesn't work ! The panels seem to be created, but I can't see them
> on the form. Am I forgetting something ? There is another way to create an
> array of TPanel with a TCheckBox in it ?

> Thanks in advance,

> Carlos I. Molina
> carlosimol...@hotmail.com

Re:Can't create an array of TPanel


Quote
Carlos I. Molina wrote in message <7qslr9$m...@forums.borland.com>...
>    aPnl[iCt] := TPanel.Create(Self);
>    aPnl[iCt].Left       := 4;
>    aPnl[iCt].Top        := 36 + (37 * iCt);
>    aPnl[iCt].Font       := pnlT.Font;
>    aPnl[iCt].Width      := pnlT.Width;
>    aPnl[iCt].Height     := pnlT.Height;
>    aPnl[iCt].BevelInner := pnlT.BevelInner;
>    aPnl[iCt].BevelOuter := pnlT.BevelOuter;
>    aPnl[iCt].Visible    := True;

    aPnl[iCt].Parent := Self;

Quote
>    aChk[iCt] := TCheckBox.Create(aPnl[iCt]);
>    aChk[iCt].Top     := 4;
>    aChk[iCt].Left    := 4;
>    aChk[iCt].Checked := False;

    aChk[iCt].Parent := aPnl[iCt];

--
Wayne Niddery - WinWright Consulting
RADBooks - http://members.home.net/wniddery/
Bill of NO Rights; Bill of NO Rights; ARTICLE VII: You do NOT have the right
to the possessions of others. If  you rob, cheat or coerce away the goods or
services of other citizens, don't be surprised if the rest of us get
together and lock you way in a place where you still won't have the right to
a big-screen color TV or a life of leisure.

Other Threads