What is the accepted way to use frames in Delphi?

You can even go a step further, by registering your frames as components.

That disallows you to edit properties of components on the Frame as soon as the Frame component is on the form. But I think that is a good thing.

You need to one more thing than registering your frame as a component, as I explain in this article about Delphi – Frames as visual Components – don’t forget your Sprig!.

That knowledge is not mine: I got it from Ray Konopka during one of his sessions at the Delphi Live conference in San Jose earlier this year.


That's one way, and there is nothing wrong with it. Another way, is to to do it visually. So you can basically add the frame to a form. to do this you :

  • Create your Frame.
  • Go to the form you wish to put your frame on.
  • Add a Frames component (Standard Tab)
  • Choose your frame from the drop down.
  • That's it!

The only problem with your approach is that you cannot add multiple instances of the same frame to a given form:

Frame1 := TMyFrame.Create(Self);
Frame1.Parent := Self;
// ...
Frame2 := TMyFrame.Create(Self); // bombs out with "a component with the name MyFrame already exists"

The workaround for his is to assign a different name for each instance:

Frame1 := TMyFrame.Create(Self)
Frame1.Parent := Self;
Frame1.Name := "FirstFrame";
// ...
Frame2 := TMyFrame.Create(Self); // works now, there is no name conflict

Tags:

Delphi

Tframe