Gustav Schubert 25 Posted April 16, 2020 FMX feature: If you inherit from TPanel twice it becomes transparent, like TLayout. Context: I have a base class which inherits from TPanel. And then I actually use a class that inherits from that base class. I think I will use a TLayout, but do you have an explanation why my Panel is loosing style? unit Unit1; interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Controls.Presentation, FMX.StdCtrls, FMX.Layouts; type // TSpeedPanelClass = TToolbar; // TSpeedPanelClass = TLayout; TSpeedPanelClass = TPanel; TSpeedPanelBase = class(TSpeedPanelClass); TSpeedPanel = class(TSpeedPanelBase); TForm1 = class(TForm) Button1: TButton; Button2: TButton; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private Counter: Integer; Y: Integer; procedure InitSpeedPanel(sp: TSpeedPanelClass); procedure SpeedButtonClick(Sender: TObject); end; var Form1: TForm1; implementation {$R *.fmx} procedure TForm1.FormCreate(Sender: TObject); begin Button1.Position.X := 24.0; Button1.Position.Y := 8.0; Button2.Position.X := 112.0; Button2.Position.Y := 8.0; Fill.Color := TAlphaColors.Cornflowerblue; Fill.Kind := TBrushKind.Solid; Y := 50; end; procedure TForm1.Button1Click(Sender: TObject); var sp: TSpeedPanelClass; begin sp := TSpeedPanelBase.Create(Self); InitSpeedPanel(sp); end; procedure TForm1.Button2Click(Sender: TObject); var sp: TSpeedPanelClass; begin sp := TSpeedPanel.Create(Self); InitSpeedPanel(sp); end; procedure TForm1.InitSpeedPanel(sp: TSpeedPanelClass); var sb: TSpeedButton; begin Inc(Counter); sp.Parent := Self; sp.Position.X := 0; sp.Position.Y := Y; sp.Height := 40; sp.Width := 200; sb := TSpeedButton.Create(sp); sb.Parent := sp; sb.Text := 'SpeedButton' + IntToStr(Counter); sb.Tag := Counter; sb.OnClick := SpeedButtonClick; Y := Y + 50; end; procedure TForm1.SpeedButtonClick(Sender: TObject); begin Caption := Format('Btn %d clicked.', [(Sender as TComponent).Tag]); end; end. Share this post Link to post
vfbb 285 Posted April 16, 2020 Because your stylelookup is empty and the default stylelookup of the TPanel is the 'panelstyle', and your new component don't have a default style. Just do this: procedure TForm1.InitSpeedPanel(sp: TSpeedPanelClass); var sb: TSpeedButton; begin sp.StyleLookup := 'panelstyle'; // <<<<<<<<< // ... 1 1 Share this post Link to post
Gustav Schubert 25 Posted April 16, 2020 Setting StyleLookup to 'panelstyle' works, but the question remains - why is it not needed in a direct descendant? Share this post Link to post