Recent

Author Topic: Form inside form  (Read 1619 times)

bpp

  • New Member
  • *
  • Posts: 16
Re: Form inside form
« Reply #15 on: May 27, 2020, 08:16:19 pm »
I'm trying some tests with frames ...

i used a panel to show the frame, and two buttons in main form:

Code: Pascal  [Select][+][-]
  1. procedure TfrmMainForm.btnShowClick(Sender: TObject);
  2. begin
  3.   pt:= TfrmFrame.Create(frmMainForm.Panel1);
  4.   with pt do
  5.   begin
  6.     Align:= alClient;
  7.     Parent:= frmMainForm.Panel1;
  8. end;  
  9.  


Code: Pascal  [Select][+][-]
  1. procedure TfrmMainForm.btnCloseClick(Sender: TObject);
  2. begin
  3.   pt.free;
  4. end;

this is the approach i have to do for all the other forms?
what problems can happen when the software starts to growing up?

Thanks
« Last Edit: May 27, 2020, 09:08:14 pm by bpp »

howardpc

  • Hero Member
  • *****
  • Posts: 3448
Re: Form inside form
« Reply #16 on: May 27, 2020, 08:38:26 pm »
You should not ever call pt.Free manually, because you made frmMainForm.Panel1 its Owner when you created it.

If you want to control the moment of its destruction yourself, create it with a Nil Owner.

bpp

  • New Member
  • *
  • Posts: 16
Re: Form inside form
« Reply #17 on: May 27, 2020, 09:16:40 pm »
Code: Pascal  [Select][+][-]
  1. ...
  2.  pt:= TfrmFrame.Create(Nil);
  3. ...
  4.  
  5.  
  6. ...
  7. FreeAndNil(s);
  8. ...
  9.  

like that?

lucamar

  • Hero Member
  • *****
  • Posts: 2921
Re: Form inside form
« Reply #18 on: May 27, 2020, 09:29:25 pm »
Yes, like that. :)

The Owner thing can be viewed (very, very basically) as just a gimmick to let you forget to free/destroy components: the Owner takes that responsibilty on its own, which is nice for long-lived objects inside "container" controls (forms, frame, panels, etc.).

But that means that you should really forget releasing them on your own, so if you want to do that (control the whole life-cycle of a component) then you should assign no Owner to it.

It shouldn't matter much, since a possible Owner should be programed in such way so at to recognize when an owned component is no longer there. Of course, "should" doesn't mean all of them "do" it, so better safe than sorry ;)
« Last Edit: May 27, 2020, 09:31:24 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.8/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

howardpc

  • Hero Member
  • *****
  • Posts: 3448
Re: Form inside form
« Reply #19 on: May 27, 2020, 10:52:27 pm »
Code: Pascal  [Select][+][-]
  1. ...
  2.  pt:= TfrmFrame.Create(Nil);
  3. ...
  4.  
  5.  
  6. ...
  7. FreeAndNil(s);
  8. ...
  9.  

like that?
No, like this:
Code: Pascal  [Select][+][-]
  1. ...
  2.  pt:= TfrmFrame.Create(Nil);
  3. ...
  4.  
  5.  
  6. ...
  7. FreeAndNil(pt);  // or just pt.Free;
  8. ...
  9.  

dbannon

  • Hero Member
  • *****
  • Posts: 1070
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Form inside form
« Reply #20 on: May 28, 2020, 03:12:56 am »
Can you please elaborate on how to get a "general purpose" frame onto an existing form ?
You mean a "generic" frame you built, say, a year ago for another project and that you want to use in a new one? There are several ways to do that, but they all end up in adding the frame unit (and lfm) to your project, just as with a normal form.

No, a new, almost empty unit containing only the code to make the frame. I made that unit, added it to the project in project inspector but still, when I click a form in the project, I have to choose to use an existing (and inappropriate) frame, not the empty one I just created and not, as I expected, an empty one ready for me to start adding things to.

So, just so I understand (I have abandoned the idea for now) can I ask -
  • How do we use the TFrame from the component palette, does it require a "template" (for lack of a better word) frame already defined somewhere in the project ?
  • If the above is 'yes', how do we make that template so that the TFrame and its friend the Object Inspector can find it at design time ?

It does sound like a useful technique to me, especially as a means of breaking up an excessively large unit. If I can make it work, I'll have a hack at the wiki.

Davo
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

lucamar

  • Hero Member
  • *****
  • Posts: 2921
Re: Form inside form
« Reply #21 on: May 28, 2020, 05:49:06 am »
To use frames you have first to design/create them; the process is very similar to adding a new form: Go to the "File" menu, select "New..." and in the dialog that appears select "Frame"; a new frame and its unit will be created, as if it were a form, so you can start setting its properties, adding controls, event handlers, etc.

Once your frame is done you select the "TFrame" button in the palette, drop it on some form and a dialog appears allowing you to select the one you want.

It's that easy :)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.8/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

dbannon

  • Hero Member
  • *****
  • Posts: 1070
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Form inside form
« Reply #22 on: May 28, 2020, 10:31:56 am »
To use frames you have first to design/create them; the process is very similar to adding a new form: Go to the "File" menu, select "New..." and in the dialog that appears select "Frame"; a new frame and its unit will be created, as if it were a form, so you can start setting its properties, adding controls, event handlers, etc.
Once your frame is done you select the "TFrame" button in the palette, drop it on some form and a dialog appears allowing you to select the one you want.

OK, thanks Lucamar, thats what I have been doing and it does not, at any stage, offer me that frame when dropping a TFrame from the palette.

When I have some time, I will try it in a simpler project, maybe there is something about my project that is blocking its behaviour.

Davo
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

bpp

  • New Member
  • *
  • Posts: 16
Re: Form inside form
« Reply #23 on: May 28, 2020, 06:01:08 pm »
It’s better use a TFrame to show the frames then a panel?

what’s the diference between them?
« Last Edit: May 28, 2020, 06:05:03 pm by bpp »

 

TinyPortal © 2005-2018