What is the correct way to create and add components at runtime ?

That code is only valid within a constructor. The question was specifically asking how to do it dynamically, outside of a constructor. :wink: