Lars Fosdal 1792 Posted January 23, 2019 When creating frames runtime in VCL, there are a set of tweaks that need to be applied to make the frame behave properly after creation (setting parent/owner etc). Are there similar tricks needed for FireMonkey, and are there other pitfalls related to dynamically creating frames at runtime? Is it better to drop the frames on the main form at design time? 1 1 Share this post Link to post
Rollo62 536 Posted January 23, 2019 (edited) I was also hesitating to use Frames for many years, from some bad experieces under VCL, and especially in Designmode. For FMX I use Frames in some places very successfully, where I use designer to design them same like a form, and loading only via runtime into TRectangles. I checked also other carriers, like TPanel, TLayout, they all seems to work well. Since also the TFrameStand uses Frames as visual container, I feel quite sure about them now. I also use Interface with Frames, so that I'm able to create the frame in a factory, and using them via Interface elsewhere. Still I don't use Frames in Designmode, like dropping a component, since I think there are a lot of misconceptions. With good encapsulations, at runtime, they behave quite well, and I even can embed frames into frames in same way. Rollo Edited January 23, 2019 by Rollo62 1 1 Share this post Link to post
Lars Fosdal 1792 Posted January 23, 2019 @Rollo62 Can you exemplify how you "load via runtime into TRectangles" ? In my current app, I want to instantiate the frame onto a TTabItem. Share this post Link to post
Dalija Prasnikar 1396 Posted January 23, 2019 Creating at run-time is pretty straightforward. You need Owner and Parent, and sometimes setting Align property. You can use any FMX control as those - or at least I have been able to use them without a problem. FFrame := TMyFrameClass.Create(AParent); FFrame.Parent := AParent; FFrame.Align := ... And that is it. 4 1 Share this post Link to post
Lars Fosdal 1792 Posted January 23, 2019 So basically just like for VCL. Nice. Share this post Link to post
Christen Blom-Dahl 7 Posted January 23, 2019 @Lars Fosdal, you should take a look at https://blog.andreamagni.eu/2015/09/tframestand-component-fmx-tframes-on-steroids/ It is a very nice extension to use frames in Firemonkey. 1 Share this post Link to post
Rollo62 536 Posted January 23, 2019 This works well for me in many places procedure Frame_Embed_To(const AFrame : TFrame; const ACarrier : TControl); begin if Assigned( ACarrier ) and Assigned( AFrame) then begin ACarrier.BeginUpdate; try AFrame.Parent := nil; AFrame.Parent := ACarrier; AFrame.Align := TAlignLayout.Client; finally ACarrier.EndUpdate; ACarrier.Repaint; end; end; end; procedure Frame_Embed_ReleaseFrom(const AFrame : TFrame; const ACarrier : TControl); begin if Assigned( ACarrier ) and Assigned( AFrame) then begin ACarrier.BeginUpdate; try AFrame.Parent := nil; finally ACarrier.EndUpdate; ACarrier.Repaint; end; end; end; 2 1 Share this post Link to post
John Kouraklis 94 Posted January 23, 2019 I use Frames in FMX all the time. No problems in general. You can set the Align property in the frame directly. So no need to set it in code Share this post Link to post
John Kouraklis 94 Posted January 23, 2019 TFrameStand is very convenient indeed But it kills any animation you've got in your frames. Share this post Link to post
Mavarik 6 Posted January 23, 2019 (edited) 9 hours ago, Rollo62 said: I was also hesitating to use Frames for many years, from some bad experieces under VCL, and especially in Designmode. That's why I did not use frames at all... But with FMX there is no need for a "frame". For every content I create a Form with a TLayout. If there is any need to uses this content on a other form/tab/whatever, you just have to set the parent of the layout to the e.g. tab or any other layout on any other form. So easy... Frank Edited January 23, 2019 by Mavarik 4 1 Share this post Link to post
Rollo62 536 Posted January 24, 2019 (edited) Yes, I did use Forms too, before switching more and more to Frames. Works well either. In new projects I will have 1 main form, and the rest of the views will be done in frames. Anyway, Frames should be more lightweight, and for me proofed to be stable under FMX. I think the biggest problem with Frames at all is: If you try to use them as component by the IDE-Designer, this will end up in crash sooner or later with a lot of headache. Edited January 24, 2019 by Rollo62 Share this post Link to post
sjordi 39 Posted May 24, 2022 @Mavarik offers a nice solution. I use TFrameStand too. The advantage here is that you can create the frame only when you need it, no other one is created before being used. And it's released once you leave it. The advantage of Maverick solution is that you can switch the appearance of the form at design time between Windows, mac, iOS and Android. This is not possible with Frames... But I have no problems using stands. Share this post Link to post