Jump to content
Lars Fosdal

Request for advice: FireMonkey and Frames

Recommended Posts

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?

  • Like 1

Share this post


Link to post

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 by Rollo62
  • Like 1

Share this post


Link to post

@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

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.

  • Like 3

Share this post


Link to post

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;

 

  • Like 2

Share this post


Link to post

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
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 by Mavarik
  • Like 4

Share this post


Link to post

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 by Rollo62

Share this post


Link to post

@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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×