• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1798
  • Last Modified:

Delphi - Frames - Dymanically removing and adding

Hello,

Just using a basic scenario, lets assume that we have a single form with 2 buttons.  One button says 'display frame one' while the other says 'display frame two'.  In our project, we also have 2 frames (FrameOne and FrameTwo).

How do I display FrameOne when the first button is clicked, and then remove it and display FrameTwo when the second button is clicked.  I think I have the 'remove old frame' right, so I basically just need the 'create new frame' method.  In both cases, the frames are the same size and should be displayed on the same location on the form.
0
Sebastion
Asked:
Sebastion
  • 2
  • 2
1 Solution
 
mikelittlewoodCommented:
I used a groupbox to display the frames inside

procedure TForm1.Button1Click(Sender: TObject);
begin
  if frame1 = nil then
    frame1 := Tframe1.Create(GroupBox1);

  frame1.Parent := GroupBox1;
  frame1.Align := alClient;
  frame1.Show;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  if frame2 = nil then
    frame2 := Tframe2.Create(GroupBox1);

  frame2.Parent := GroupBox1;
  frame2.Align := alClient;
  frame2.Show;
end;
0
 
SebastionAuthor Commented:
Hey Mike,

From what I gather, you're using two different variables (frame1 and frame2).  Is it possible to use just a single variable declared as a TFrame?

Also, with this method, are you just overwriting frame1 with frame2 (and vis versa), or are you freeing up the frame before writing in the new one?
0
 
SebastionAuthor Commented:
I guess what I mean is whether .free is enough when closing a frame, before opening another.
0
 
mikelittlewoodCommented:
Yes I am using 2 different frames, but I just assumed that would be what you are doing.
If your using the same frame twice, you would just need to referesh visual details, but then it wouldnt be worth using frames at all.

Yes you can just Free and Nil the frame to clear the variables, depends how often you are switching as to whether you want to keep recreating the form rather than updating on form components.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now