In this particular case I'm using PowerPDF library to dynamically build a PDF document, but the same applies for the general concept of dynamically aligning controls sequentially inside of a parent control. In this library, TPRPage
is the base control to contain all element controls, in this case, sequential instances of TPRLayoutPanel
.
What I do when dynamically adding controls:
- Create a control (
TPRLayoutPanel
) - Set the control's parent (
TPRPage
) - Align the control to top (
PRLayoutPanel.Align:= alTop;
)
The problem is it gets forced to the very beginning (top) instead of the very end (bottom) of the page.
I've tried setting its order PRLayoutPanel.SendToBack;
or PRLayoutPanel.BringToFront
but with no luck.
How can I dynamically create and align multiple controls within a parent control sequentially? My only current work-around is to add the controls in reverse order (from end to beginning) which is ridiculously unnecessary.
Here's my universal function which creates every new instance of an aligned control in this parent:
function TfrmReport.InsertPanel: TPRLayoutPanel;
begin
Result:= TPRLayoutPanel.Create(PRPage);
Result.Parent:= PRPage;
Result.Align:= alTop;
Result.Height:= 40; //Default, may change later
end;
Question&Answers:os