7

Just started testing FireMonkey and can't find a way to make dynamically sized/positioned components.

VCL had the Anchor property, FM does not.

Anybody see something I missed

Update:

Simple anchoring is not available in FM. You have to create TLayouts and align those, then put the controls inside the panel to have them 'stick'. If you used older version of Builder or Delphi, this will be the same as we used to have to do with TPanels.

Gregor Brandt
  • 7,659
  • 38
  • 59
  • There is [`FMX.Types.TControl.Anchors`](http://docwiki.embarcadero.com/VCL/XE2/en/FMX.Types.TControl.Anchors), but it's private and so not available. – David Heffernan Sep 02 '11 at 15:57
  • You might want to look at the TLayout component. Looks like you drop it on the form, configure it and then drop some components into it... just a guess though. – Bob A Sep 02 '11 at 16:21
  • @Bob: alignment is not the same as anchoring. – Gregor Brandt Sep 02 '11 at 17:19
  • @Gregor: exactly. Anchoring makes a lot of sense for most uses. That one can do animation etc. is fine, but one doesn't always need or want that. Anchors would be nice. – Rudy Velthuis Sep 02 '11 at 21:30

5 Answers5

11

This is the answer to your question. The anchors property in VCL has apparently been replaced by Margins and Padding (due to performance considerations) and I found some documentation at the XE2 wiki (http://docwiki.embarcadero.com/RADStudio/en/FireMonkey_Application_Design). I doubt if anchors will be put in at a later date. To anchor two buttons (Ok and Cancel) at the bottom of a form on the right side do the following.See images below for the Ok and cancel button.

enter image description here

Place a small panel aligned to the bottom on the form, say about 40 height. Set the 'Margins' on the bottom panel to create a smaller space in which the buttons will live, make sure you set the align the button to alRight. For example the gap between the right edge of the form and the right most button has a margin of 15. The top and bottom margins were set to 12. That anchors the right most button.

'Padding' is the opposite to a margin, the padding puts space outside the control. To the right most button I added a padding of 20 to the left side, this will be the space between the two buttons. For the second button to the left of the first all we need to do is set the align property to alRight, no need to adjust the padding or margins.

rhody
  • 2,274
  • 2
  • 22
  • 40
8

Drop multiple TLayout components on the form and configure their alignment properties as desired. Drop other components into these layouts and set their alignment properties relative to the TLayout they are contained in. Seems to be working for me...

Bob A
  • 346
  • 2
  • 5
  • That for component alignment, not component anchoring. For instance if I need am OK button to stay the same size but follow lower right window resizing. Alignment does not do that. – Gregor Brandt Sep 02 '11 at 17:06
  • @Gregor Maybe I just don't understand... If I drop a TLayout on the Form and set it's Alignment to alBottom the drop a TButton onto the TLayout and set it's alignment to alRight it follows the form's resizing nicely. – Bob A Sep 02 '11 at 17:24
  • that appears to work but makes GUI design a pain. Simple anchoring is no longer available, now I have to create TLAyouts. This is like the old days with TPanels to get things to stay where you want them. Welcome to 1990 – Gregor Brandt Sep 02 '11 at 17:27
  • 4
    @Gregor- Simple anchoring probably won't play well with the scaling, animation and 3D features of this new FireMonkey frameworks... – Bob A Sep 02 '11 at 17:32
  • @Bob A: why not? It is clear that some of the effects should not be combined, so anchoring should not be combined with motion animation. That's common sense, IMO. – Rudy Velthuis Sep 02 '11 at 21:28
  • @Rudy - Just an uneducated guess on my part... I've only had a chance to play with FireMonkey for about 4 hours this afternoon. I'll tell you this, I am blown away by the potiental of it. I think everyone involved has done an impressive job with this release of Delphi. :) – Bob A Sep 02 '11 at 22:59
5

Here's the answer you are looking for: FMX controls do not have anchors.

I imagine this will be a "next version" feature.

Nick Hodges
  • 16,902
  • 11
  • 68
  • 130
1

A quick look at the align property reveals many more choices than we had in previous Delphi versions:

enter image description here

Doesn't that solve your problem (at least partially).
I remember getting by OK for a long time just using nested panels and align to layout stuff.

Johan
  • 74,508
  • 24
  • 191
  • 319
  • isn't that a huge step backwards. I have to nest TLayouts to get anchoring. If I recall from my Builder 5 days, that was a huge pain in the *ss – Gregor Brandt Sep 02 '11 at 17:21
  • 1
    It is, but at least that does not make Firemonkey useless, it just means there's room for improvement. Everybody was screaming to release all those promised features already. It's even in the files (see `http://docwiki.embarcadero.com/VCL/XE2/en/FMX.Types.TControl.Anchors`, however I guess they haven't ironed out all the bugs yet, so they've made those Anchors private. In time all will be right. I for one am tickled pink with the chance to write for iOS (where there is no resizing :-). – Johan Sep 02 '11 at 17:48
  • "isn't that a huge step backwards"...oh common - just continue to use VCL if you're not ready for something new. There are so much great things in Firemonkey and this is the first release of it...of course there are still some issues...far away from being useless IMHO – jpfollenius Sep 04 '11 at 07:44
0

You can use LiveBindings and expressions to set the properties of your control based on the parent control, though it's a lot of work.

Otherwise, use Margins and Padding (like HTML/CSS).

Marcus Adams
  • 53,009
  • 9
  • 91
  • 143