Jump to content
Sign in to follow this  
Gustav Schubert

Which component to use as base class for SpeedPanel

Recommended Posts

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

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'; // <<<<<<<<<
  // ...

 

  • Like 1
  • Thanks 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×