Recent

Author Topic: [SOLVED] Lazarus Show/Hide multiple frames from a form  (Read 959 times)

jex

  • New Member
  • *
  • Posts: 23
[SOLVED] Lazarus Show/Hide multiple frames from a form
« on: April 03, 2020, 05:06:02 am »
Hello,

Started to learn pascal/lazarus and I'm struggling to create a form that has buttons and for each button it shows a specific frame.
I've seen and used the example code from the wiki but it's creating problems for me:

1. When switching between frames, unhandled exception shows that 'frame1 already exists', and sometimes shows error SIGSEGV. I've made several attempts and searched but no help.
2. I reached a somewhat working stage but unwanted behavior appears: say Frame1 is already showing, when i click the button that shows it, it reloads, how to avoid that?
3. I don't want to Free a frame to show the other or FreeAndNil everything, is there a way to just Show/Hide each frame? or is that a bad practice and can lead to memory leaks?

I've attached a sample project of what I'm trying to do. Any help is greatly appreciated
« Last Edit: April 03, 2020, 04:05:11 pm by jex »

eljo

  • Sr. Member
  • ****
  • Posts: 358
Re: Show/Hide multiple frames from a form
« Reply #1 on: April 03, 2020, 06:21:36 am »
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   if Assigned(Frame) then begin
  4.     Frame.Free;
  5.   end;
  6.   Frame := TFrame1.Create(Panel1);
  7.   Frame.Parent := Panel1;
  8. end;
  9.  
  10. procedure TForm1.Button2Click(Sender: TObject);
  11. begin
  12.   if Assigned(Frame) then begin
  13.     Frame.Free;
  14.   end;
  15.   Frame := TFrame2.Create(Panel1);
  16.   Frame.Parent := Panel1;
  17. end;
  18.  
  19. procedure TForm1.Button3Click(Sender: TObject);
  20. begin
  21.   if Assigned(Frame) then begin
  22.     Frame.Free;
  23.   end;
  24.   Frame := TFrame3.Create(Panel1);
  25.   Frame.Parent := Panel1;
  26. end;
  27.  
« Last Edit: April 03, 2020, 06:24:32 am by eljo »

jex

  • New Member
  • *
  • Posts: 23
Re: Show/Hide multiple frames from a form
« Reply #2 on: April 03, 2020, 04:04:16 pm »
eljo, many thanks! that works perfectly.

 

TinyPortal © 2005-2018