How to run code when a TFrame is created?

105 views Asked by At

I need to run code when a TFrame is created, not when the frame shows, or when the parent form is created. I don't see any event handler for OnCreate for my TFrame.

How would one then be able to run code when a frame is created?

I am using Delphi 11.3 and my project is using FMX (Firemonkey)

1

There are 1 answers

0
Json Dabbler On

Simply override the virtual Create() constructor or virtual AfterConstruction() method.

To override the Create() constructor, add constructor Create(AOwner: TComponent); override; into your frame's private declarations and then press Ctrl+Shift+C to create the constructor below. It should create something like this:

constructor TMyFrame.Create(AOwner: TComponent);
begin
  inherited;
  // Your code goes here that runs when the frame is created
end;