What is the use of the Align and Anchor properties on TForm?

You can set the alignment to TForm, for example, set one form to alTop, and the other to alClient - while two forms occupy the entire area of ​​the screen in an obvious way. Is this a reasonable thing in the app?

I also notice that the bindings are exposed on the forms, but I can't think they will be useful (permission changes? MDI apps?) Any ideas?

Edit: I made a video about this post to make it all the more clear.

+6
source share
4 answers

You can use TForm as a regular control by setting its Parent property:

 procedure TForm1.Button1Click(Sender: TObject); begin frmEmbed:= TForm.Create(Self); frmEmbed.Parent:= Self; frmEmbed.Width:= 50; frmEmbed.Height:= 50; frmEmbed.Align:= alRight; frmEmbed.Anchors:= [akLeft, akBottom]; frmEmbed.Visible:= True; end; 

you should comment out the line frmEmbed.Align:= alRight; to find out how the Anchors property works.


If you're interested in where the above is used: the parent form without a header is an alternative to TFrame ; frameworks were not available with earlier versions of Delphi, so parental forms were used instead. You can find them in legacy code.

+15
source

You can place the form inside another form. I don’t know how well this works. In Delphi1, there were special third-party controls for directing the event. Today, he seems to be more or less working out of the box, with the exception of modal dialogs. Try it like this:

 procedure TMainForm.Button1Click(...); begin with TForm.Create(Self) do begin Caption := 'Internal one'; Parent := Self; Visible := True; end; end; 

Perhaps snapping and alignment would make sense in this setting. Later, this is similar to how the new single-window IDE is implemented.

+3
source

One simple case - for a carefree form (for example, the style of the megalopolis win-8), you can attach the exit button to the upper right corner.

But it’s best to use a simplified shape that responds to resizing ... Using akLeft and akRight, you can horizontally fill the gap horizontally. Using all 4 anchors is similar to setting up a client for an alternative, just without having to surround it with other panels.

Much of what you can do with anchors can also be done with many panels, but as the shape becomes more complex, it becomes messy, sometimes requiring several levels of panels on the panels.

Of course, using a combination of panels and anchors will often be the best answer.

+2
source

You can place the form inside any other component of the container.

This is useful for docking, fi you can attach forms on the page control tabs or anywhere.

It is also useful as an alternative to TFrame: if you create a frame as TForm and not TFrame, it will not be embedded at design time and therefore cannot be edited / sabotaged by the development time editor.

Built-in TFrames can override their properties or events in the form in which they are embedded, and this is not always desirable or practical, especially if you want the frame to be easily updated or refactored. Changed properties of inline frames end in DFM, not PAS, and therefore do not appear at compile time and do not just refactor / rename / etc.

+1
source

Source: https://habr.com/ru/post/927314/


All Articles