Recent

Author Topic: How to free form inside of panel?  (Read 3904 times)

dasa2

  • New member
  • *
  • Posts: 9
How to free form inside of panel?
« on: January 23, 2018, 07:27:16 pm »
Hi, I use 2 public procedures to view and delete forms in a panel.

To create form:
Code: Pascal  [Select][+][-]
  1. procedure TfrmMain.CreateAndShowForm(Form: TForm; FormClass: TFormClass);
  2. begin
  3.   CloseActiveForm;
  4.  
  5.   Form:=FormClass.Create(Application);
  6.   Form.BorderStyle:=bsNone;
  7.   Form.Align := alClient;
  8.   Form.Parent:= pnMain;
  9.   Form.visible := True;
  10.  
  11.   Self.Caption:=Form.Caption;
  12. end;

To remove form:
Code: Pascal  [Select][+][-]
  1. procedure TfrmMain.CloseActiveForm;
  2. begin
  3.      while pnMain.controlcount > 0 do
  4.            pnMain.controls[0].Free;
  5. end;

From TfrmMain where the panel (pnMain) is in, I can create and delete forms by calling the procedures, but when I try to call the procedures from the form displayed in the panel, I get External: SIGSEGV when I try to delete the form and create another form using:
Code: Pascal  [Select][+][-]
  1. frmMain.CreateAndShowForm(Nil, TfrmStart);

Handoko

  • Hero Member
  • *****
  • Posts: 5158
  • My goal: build my own game engine using Lazarus
Re: How to free form inside of panel?
« Reply #1 on: January 23, 2018, 07:32:52 pm »
Hello dasa2,
Welcome to the forum.

You put a form inside a panel of a form?
Wow, I never tried it. But it sounds not okay to me.
Maybe you should try using TFrame:

http://lazarus-ccr.sourceforge.net/docs/lcl/forms/tframe.html

Or using TPageControl or TNotebook.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: How to free form inside of panel?
« Reply #2 on: January 23, 2018, 08:06:22 pm »
From TfrmMain where the panel (pnMain) is in, I can create and delete forms by calling the procedures, but when I try to call the procedures from the form displayed in the panel, I get External: SIGSEGV when I try to delete the form and create another form using:
Code: Pascal  [Select][+][-]
  1. frmMain.CreateAndShowForm(Nil, TfrmStart);

Of course you get a SIGSEGV.
Code: Pascal  [Select][+][-]
  1. CreateAndShowForm(Nil, TfrmStart);
translates into
Code: Pascal  [Select][+][-]
  1. begin
  2.   CloseActiveForm;
  3.  
  4.   Nil:=TfrmStart.Create(Application);
  5.   ...

which is a complete nonsense.

Parenting a form to a TWinControl is a curious, non-standard behaviour.
As Handoko writes, far better to use TFrames or TCustomControls which are designed to need a parent.

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: How to free form inside of panel?
« Reply #3 on: January 23, 2018, 08:07:13 pm »
I'm curious, what's the main reason of doing this ???
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

dasa2

  • New member
  • *
  • Posts: 9
Re: How to free form inside of panel?
« Reply #4 on: January 23, 2018, 09:03:05 pm »
From TfrmMain where the panel (pnMain) is in, I can create and delete forms by calling the procedures, but when I try to call the procedures from the form displayed in the panel, I get External: SIGSEGV when I try to delete the form and create another form using:
Code: Pascal  [Select][+][-]
  1. frmMain.CreateAndShowForm(Nil, TfrmStart);

Of course you get a SIGSEGV.
Code: Pascal  [Select][+][-]
  1. CreateAndShowForm(Nil, TfrmStart);
translates into
Code: Pascal  [Select][+][-]
  1. begin
  2.   CloseActiveForm;
  3.  
  4.   Nil:=TfrmStart.Create(Application);
  5.   ...

which is a complete nonsense.

Parenting a form to a TWinControl is a curious, non-standard behaviour.
As Handoko writes, far better to use TFrames or TCustomControls which are designed to need a parent.

Sry, frmMain.CreateAndShowForm(frmStart, TfrmStart);


I try to create an application where I can view different forms without opening them in new windows. However, only one form may be available at a time.

I think it's like an MDI but without the ability to switch between the forms, maximize, minimize, and so on. Or as a website where every web page here is a form.

I need a nudge in the right direction.

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: How to free form inside of panel?
« Reply #5 on: January 23, 2018, 09:08:53 pm »
You can dock any form to panel:
Code: Pascal  [Select][+][-]
  1. Form2.Dock(Panel, Panel.ClientRect);
and undock
Code: Pascal  [Select][+][-]
  1. Form2.Dock(nil, Rect);
where Rect is new size anmd position of the Form2.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Handoko

  • Hero Member
  • *****
  • Posts: 5158
  • My goal: build my own game engine using Lazarus
Re: How to free form inside of panel?
« Reply #6 on: January 24, 2018, 04:09:22 am »
I try to create an application where I can view different forms without opening them in new windows. However, only one form may be available at a time.

If the layout is simple then you may use TNotebook. If it is complicated you can use TFrame. Here I wrote a demo showing how to use TNotebook to avoid using multi-forms:

http://forum.lazarus.freepascal.org/index.php/topic,39769.msg274036.html#msg274036

alaa123456789

  • Sr. Member
  • ****
  • Posts: 260
  • Try your Best to learn & help others
    • youtube:
Re: How to free form inside of panel?
« Reply #7 on: December 22, 2020, 05:13:47 pm »

 

TinyPortal © 2005-2018