I am developing a component from Tpanel that creates a number of TButtons on runtime. Each button can be added, deleted, moved and their size can be changed too during the life of the component.

I am developing a component from Tpanel that creates a number of TButtons on runtime. Each button can be added, deleted, moved and their size can be changed too during the life of the component.

Which is the best way to manage this ?
- Tlist
- TComponent
- TArray or similar

Comments

  1. Thomas Mueller I meant to ask whether you meant "owner" or "parent". You typed parent ("It doesn't need to "own" the buttons because you probably make the panel the parent of them.") - pretty sure you meant owner. So that when the panel (the new component) is destroyed the buttons on it are destroyed.

    ReplyDelete
  2. Oops, actually I meant both, but you are right: Ownership is the important one for memory management, so I should have written "make the panel the owner of them".

    ReplyDelete
  3. I use the Controls list in simple cases. If i need faster and or more convenient access to those children i mirror that with a more advanced collection (non owning) the nature of depending on requirements.

    In much more complex scenarios it may be wise to preemt vcl freeing.

    ReplyDelete

Post a Comment