Adding component to Firemonkey custom styles at runtime

  

I am making a custom list box for firemonkey.There I have customized a TSeachBox. In my custom style there is a TRectangle where i need to add TLabel at runtime.

I can add Lables at design time. But I can not see all the lables which are added at design time in this TRectangle. I’ve properly set the parent and owners of all the lables.

Any idea ?

below is the code :

procedure TCustomListBox.ColumnsChanged(Sender: TObject);
var
lPanel : TPanel;
lLabel: TLabel;
iCount : Integer;
begin
if Assigned(FSearchBox) then
Begin
if FSearchBox.FindStyleResource(‘headerstyle’) <> nil then
lPanel := FSearchBox.FindStyleResource(‘headerstyle’) as TPanel;

if Assigned(lPanel) and (lPanel is TPanel) then
begin
//Clear all the columns except whose Tag = 1
for iCount := lPanel.ChildrenCount – 1 downto 0 do
begin
if Assigned(lPanel.Children[iCount]) then
begin
if (lPanel.Children[iCount]).Tag = 0 then
lPanel.Children[iCount].Free;
end;
end;
iXPosition := 45;
//FColumns1 is columns which needs to be added.
for iCount := 0 to FColumns1.Count – 1 do
begin
FLabel := TLabel.Create(lPanel);
FLabel.Parent:= lPanel;
FLabel.Name := ‘Col’ + IntToStr(iCount);
FLabel.Visible := True;
FLabel.Position.X := iXPosition;
FLabel.Align := TAlignLayout.alLeft;
FLabel.Text := FColumns1[iCount].ColumnHeaderText;
FLabel.Width := FColumns1[iCount].ColumnWidth;
iXPosition := iXPosition + FColumns1[iCount].ColumnWidth;
end;
end;
End;
end;

Comments are closed.