Subclassing TTMSFMXPageControlPage

I want to store some additional program data in each page of a TTMSFMXPageControl.

When using the standard FMX TTabControl I can inherit from TTabItem and then call TTabControl.Add(TMyType).

However the TMS component doesn't support passing the type to the AddPage method.

I think it may be possible to do this by overriding TTMSFMXCustomPageControl.GetContainerClass but I'm not sure how to do this.

Am I correct about this being the way to do this ?

hi,


Here is a complete sample that you can use to register a new class for a page and add your own properties to it. Please note that this requires the pagecontrol to be created at runtime, but you could also create your own unit that implements this code and register it, so it can be available at designtime.



unit Unit66;


interface


uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
  FMX.TMSPageControl, FMX.TMSCustomControl, FMX.TMSTabSet;


type
  TMyTabPage = class(TTMSFMXPageControlPage)
  private
    FMyProperty: Boolean;
  public
    constructor Create(Collection: TCollection); override;
  published
    property MyProperty: Boolean read FMyProperty write FMyProperty default False;
  end;


  TMyTabPages = class(TTMSFMXPageControlPages)
  protected
    function GetTabClass: TCollectionItemClass; override;
  end;


  TMyTabControl = class(TTMSFMXPageControl)
  protected
    function CreateTabs: TTMSFMXTabSetTabs; override;
  end;


  TForm66 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;


var
  Form66: TForm66;


implementation


{$R *.fmx}


{ TMyTabControl }


function TMyTabControl.CreateTabs: TTMSFMXTabSetTabs;
begin
  Result := TMyTabPages.Create(Self);
end;


{ TMyTabPages }


function TMyTabPages.GetTabClass: TCollectionItemClass;
begin
  Result := TMyTabPage;
end;


{ TMyTabPage }


constructor TMyTabPage.Create(Collection: TCollection);
begin
  inherited;
  FMyProperty := False;
end;


procedure TForm66.FormCreate(Sender: TObject);
var
  pg: TMyTabControl;
  p: TMyTabPage;
begin
  pg := TMyTabControl.Create(Self);
  pg.Parent := Self;


  p := TMyTabPage(pg.Pages.Add);
  p.MyProperty := True;
end;


end.

Hi Pieter

Many thanks.

Last night I did almost the same by deriving my own classes from TTMSFMXCustomPageControl and TTMSFMXPageControlContainer, and overriding TTMSFMXCustomPageControl.GetContainerClass, which worked, but your answer is better !

For some reason I missed the GetTabClass function in TTMSFMXPageControlPages !!

John

Great!