Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the accepted way to use frames in Delphi?

Tags:

delphi

tframe

I was having my usual stroll around and bumped on some frames discussions.

I'm mainly a Delphi hobbyist and not a professional, so I had to learn how to use TFrames my own way which is:

  • Create a TFrame inside its unit.
  • Add that unit to the main form Uses clause.
  • Have a private variable of that TFrame's type
  • OnCreate of the form instanciates the TFrame and attaches it to a TPanel both on the Create and .Parent
  • On one of my Actions set that TFrame.Visible := True and .BringToFront.

This is my practice after some personal deliberation.

What other ways can one use the frames?

like image 827
Gustavo Carreno Avatar asked Sep 30 '09 10:09

Gustavo Carreno


2 Answers

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!
like image 62
Steve Avatar answered Oct 15 '22 13:10

Steve


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
like image 42
dummzeuch Avatar answered Oct 15 '22 13:10

dummzeuch