-5
for y:=32 downto 1 do begin
  for x := 1 to 16 do begin
    PanelArray[x,y]:=TPanel.create(self);
    PanelArray[x,y].parent:=self;
    PanelArray[x,y].Color:=clBlack;
    PanelArray[x,y].Enabled:=true;
    PanelArray[x,y].Show;
    PanelArray[x,y].BevelOuter:=bvNone;
    PanelArray[x,y].OnClick:=Panel1Click;
    PanelArray[x,y].Visible:=true;
    PanelArray[x,y].width:=10;
    PanelArray[x,y].height:=10;
    PanelArray[x,y].Refresh;
  end;
end;
Jerry Dodge
  • 26,858
  • 31
  • 155
  • 327
mbtutu
  • 1
  • 1
    The code looks like it should be showing them just fine. Not sure why you need 512 panels layered on each other in the top-left corner of the form, but that's what this code will do. Also, what is your question? – Jerry Dodge Feb 27 '17 at 16:26
  • 3
    You are programming by trial and error. Take a step back. Pointless to use `Show` and set `Visible` to `True`. That does the same thing. In any case, the control is visible by default. Calling `Refresh` serves no purpose. Putting the panels on top of each other seems needless. Perhaps the real issue is that you can't make a themed panel be any colour other than that of the theme. But you didn't ask a question so we don't really know what you want. – David Heffernan Feb 27 '17 at 16:32
  • 1
    Is this question a dupe of http://stackoverflow.com/questions/3778161/delphi-2009-create-a-tpanel-at-runtime-and-change-its-color – David Heffernan Feb 27 '17 at 16:54

1 Answers1

3

All 512 are being created, they're just invisible. You need to set the ParentBackground to "false":

for y:=32 downto 1 do begin
  for x := 1 to 16 do begin
    PanelArray[x,y]:=TPanel.create(self);

    ///////////
    PanelArray[x,y].ParentBackground := false;
    ///////////

    PanelArray[x,y].parent:=self;
    PanelArray[x,y].Color:=clBlack;
    PanelArray[x,y].BevelOuter:=bvNone;
    PanelArray[x,y].OnClick:=Panel1Click;
    PanelArray[x,y].width:=10;
    PanelArray[x,y].height:=10;
  end;
end;

I also removed the various needless lines of code that were present in your question. Such as calling Show and Refresh, and setting Enabled and Visible.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
Dave Olson
  • 1,435
  • 1
  • 9
  • 16
  • This happens automatically when setting the `Color` property. – Jerry Dodge Feb 27 '17 at 16:35
  • No it doesn't. Try it. – Dave Olson Feb 27 '17 at 16:36
  • I did just try it before I commented. I changed the `Color` property and the `ParentBackground` property switched to `False` by itself. But then again, OP doesn't say which version of Delphi they're using, so that may be the case. I'm using Delphi 10 Seattle. It's worked that way for as long as I can remember, even Delphi 7. – Jerry Dodge Feb 27 '17 at 16:36
  • @Jerry - I'm using Berlin Update 2. What are you using? – Dave Olson Feb 27 '17 at 16:37
  • It looks like the Delphi *Designer* switches it to ParentBackground = false automatically. It does not happen at run-time. – Dave Olson Feb 27 '17 at 16:47
  • It looks like that is correct then. Which is rather odd, I would expect the same behavior in both places. – Jerry Dodge Feb 27 '17 at 16:57