Author Topic: Is this safe, changing from a TFORM to a TFRAME?  (Read 440 times)

jamie

  • Hero Member
  • *****
  • Posts: 7903
Is this safe, changing from a TFORM to a TFRAME?
« on: July 16, 2026, 12:26:19 am »
I wrote a bunch of small forms that only contain just a toolbar, the idea was I could pop them in/out of a TControlBar, but I found the TFORM does not seem to integrate well doing that, so I took a bunch of forms that were made in the designer and change the base class from TFORM to TFRAME, made sure I didn't have any auto-created forms checked, rebuilt the project and it seems to manage that change.

 Is there an official way of changing the base class and not upset the designer?

 I want the designer to still work so I can manage the Toolbars and other things like Events, and I figured this is the way and I dynamically create these at run-time.

Jamie
The only true wisdom is knowing you know nothing

mas steindorff

  • Hero Member
  • *****
  • Posts: 606
Re: Is this safe, changing from a TFORM to a TFRAME?
« Reply #1 on: July 16, 2026, 03:26:09 am »
I believe forms behave differently on create than frames so you may need to update your oncreate code. Frames don't show their OnCreate in the object inspector.
Frames are more like a Tcomponent than they are Tform, you should use "constructor" as the Oncreate() replacement. I use FrameCreate() as the default constructor in my code but I do not know if that is standard.
Frames also do not have an AfterCreate() like forms do.
As the frames parent I tend to use a blank panel and pass it as the owner.  then, like other Tcompinents, they will be freed automatically. otherwise they can hold and use of the GUI parts  a form can like timers and controls.
windows 10 &11, Ubuntu 21+ IDE 3.4 general releases

Thaddy

  • Hero Member
  • *****
  • Posts: 19633
  • Glad to be alive.
Re: Is this safe, changing from a TFORM to a TFRAME?
« Reply #2 on: July 16, 2026, 07:27:57 am »
The safe way is:   add Tframe, go to the form, select all components on the form at once (keep ctrl down), cut them to clipboard, resize the frame, paste them on the frame. You may loose events, so some reconnecting is likely.
You can't simply change the ancestor from Tform to Tframe.
« Last Edit: July 16, 2026, 07:35:33 am by Thaddy »
Any "programmer" that knows only one programming language is not a programmer

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12984
  • FPC developer.
Re: Is this safe, changing from a TFORM to a TFRAME?
« Reply #3 on: July 16, 2026, 08:39:53 am »
I've done this many times both ways (frame to form and vice versa), mostly in Delphi, but also in Lazarus. Sometimes you get a warning that properties are unknown, and the form dimensions in the designer are fscked, but that is about it.

Thaddy

  • Hero Member
  • *****
  • Posts: 19633
  • Glad to be alive.
Re: Is this safe, changing from a TFORM to a TFRAME?
« Reply #4 on: July 16, 2026, 10:29:55 am »
@marcov
Hence I wrote: resize the frame. That is a catcha.
Any "programmer" that knows only one programming language is not a programmer

mas steindorff

  • Hero Member
  • *****
  • Posts: 606
Re: Is this safe, changing from a TFORM to a TFRAME?
« Reply #5 on: July 16, 2026, 08:46:31 pm »
I find it's easier to size a frame by placing it on a panel (aka set panel as owner) and then set the frames .Aliign := alClient ; then I not only have blank on where it will be created at run time but I can also use the anchors interface of the object inspector (of the panel) to handle any auto sizing I may wish the frame to have. here is the fames code
Code: Pascal  [Select][+][-]
  1. constructor TBaseFrame.FrameCreate(TheOwner: Tcomponent);
  2. begin
  3.   inherited create(TheOwner);
  4.   self.Parent  := TWinControl( TheOwner); // I think this is redundant
  5.   self.Align   := alClient;            
  6. ...
  7.  
and then in the form it just
Code: Pascal  [Select][+][-]
  1. procedur main.addmyFrame(num: Integer);
  2. var frm:TMyFrame;
  3. begin
  4.   frm := TMyFrame.FrameCreate(myPanel);
  5.   frm.tag := num;
  6.   ...
  7. end;
  8.  
and then add the hooks for the frame to interact with the form ...
Mas


windows 10 &11, Ubuntu 21+ IDE 3.4 general releases

 

TinyPortal © 2005-2018