Z Order of Controls in Delphi FireMonkey(Tom Yu的博客)
Get and set the Z Order of controls at runtime in Delphi FireMonkey.

This is a follow on to my earlier post where I provided a VCL solution.
Now Ive created a free FireMonkey unit that has the same get and set routines as the VCL solution. The full source code is available for download
Source and Demo Project

Full source code provided.
Download here
The demo lets you get and set the Z Order of controls and also get a list of all controls in Z Order.
The list on the right hand side shows the Z order of all controls on the form.
You can change the Z order and watch the “B” TEdit move up and down through the Z Order.
What does Delphi Provide ?
Delphi provides a limited API to set the Z order of controls.
You can bring a control to the front or send it to the back … that is all.
begin
Edit1.BringToFront;
Edit2.SendToBack;
end;
But we need to reposition a control anywhere in the Z order !
Don’t panic – we can do that using code that I provide in this post.
How does my code work ?
The code uses a brute force approach, repeatedly bringing controls to the front until they are in the requested order. It’s a primitive approach but it works well enough.
Get Z Order of a control
This is the code that you write. Pretty easy
var
vZorder : integer;
begin
vZorder:= zzGetControlZOrder (MyEdit);
end;
Modify the Z Order of a control
Another one liner. The brute force happens behind the scenes
begin
zzSetControlZOrder (MyEdit, 10);
end;
Reposition a control on top of another control
// reposition Edit1 to be on top of Edit2
begin
zzSetControlZOrder (
Edit1
,zzGetControlZOrder (Edit2) + 1
);
end;
Reposition a control below another control
// reposition Edit1 to be on top of Edit2
begin
zzSetControlZOrder (
Edit1
,zzGetControlZOrder (Edit2) - 1
);
end;
FireMonkey dummy elements
Some FireMonkey objects such as TForm and TPanel always include a child # 0 that is used to paint the background or border. Dont worry, I have coded around to ensure that these elements remain at the bottom of the list.
Close enough
In VCL – some controls such as TLabel are always positioned at the back and their Z Order can not be changed.
This is less of an issue for FireMoneky as TLabels can be brought to the front. However, I expect it will still be an issue for some controls
With this in mind, the zzSetControlZOrder function will reorder the control to as close as possible to the Z position that you specify.
Zero Based Z-Order
The Z Order is zero based, so the first control is # 0, the second control is #1.
Try to break it
You can throw any object that you like at the routines and they will survive. If you pass in something that does not have a Z-Order position, it wont do anything and it also wont crash, show an error or raise an error. The GET function will return -1. The SET function will return FALSE. I could have raised an error, but for the purposes that I built this it was more convenient to suppress all errors.
This works for …
- Tested for Delphi 10.1 Berlin and should work in many prior releases of Delphi
- Supports FMX controls on Forms, Panels and Frames – and their descendents.
Let me know if you are interested in others that dont work and Ill see what I can do.
What About VCL ?
This post is about FireMonkey.
See this post for my solution for VCL
There are minor differences between VCL and FireMonkey
1) FireMonkey creates a child TRectangle as element #0, placed at the bottom of the Z order in Forms and Panels.
2) You can not change the Z-Order for TLabel in VCL, but you can in FireMonkey
Feedback
I’m interested in your feedback. Let me know if you have an idea for improvement, find a bug or are interested in a scenario that the unit does not support.
Download
Download the demo project with full source code
https://scotthollows.com/2016/12/27/scott-hollows-z-order-of-controls-in-delphi-firemonkey-fmx/comment-page-1/#comment-41
Z Order of Controls in Delphi FireMonkey(Tom Yu的博客)的更多相关文章
- Z Order of Controls in Delphi VCL
Get and set the Z Order of controls at runtime in Delphi VCL. If you are looking for a FireMonkey so ...
- Getting Text Metrics in Firemonkey(delphiscience的博客)
Firemonkey’s abstract TCanvas class has been providing the dimensions of the bounding rectangle of s ...
- Delphi GDI或图像处理的博客
http://blog.csdn.net/w1028489713/article/category/1918251
- delphi Firemonkey ListBoxItem自绘
delphi Firemonkey ListBoxItem自绘 ListBoxItem1的事件ListBoxItem1Paint procedure TForm1.ListBoxItem1Paint( ...
- delphi Firemonkey ListView 使用参考
delphi Firemonkey ListView 使用参考 Tokyo版本 http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Customizin ...
- Delphi Firemonkey Button ImageList
Delphi Firemonkey Button ImageList 按钮图标 在上面 界面上,选择Button,放个ImageList控件,添加图标到ImageList. 然后关联Button和Im ...
- 自定义经纬度索引(非RTree、Morton Code[z order curve]、Geohash的方式)
自定义经纬度索引(非RTree.Morton Code[z order curve].Geohash的方式) Custom Indexing for Latitude-Longitude Data 网 ...
- Color gradient in Delphi FireMonkey
Introduction to color gradients in Delphi FireMonkey. Video This video covers the basics of color gr ...
- Z Order(Copy From WIN32.HLP)
The Z order of a window indicates the window's position in a stack of overlapping windows. This wind ...
随机推荐
- TensorFlow 需注意的细节问题
1. 数据类型 不带小数点的数默认为 int32,带小数点的数默认为 float32:
- 【u235】背单词
Time Limit: 1 second Memory Limit: 128 MB [问题描述] 英语四级考试临近了,小Y却发现他已经把以前学的单词几乎忘光了.好在现在离考试还有一段时间,小Y决定从现 ...
- hive 日志配置/表头配置
1.日志配置,拷贝hive/conf下的hive-log4j2.properties.template为hive-log4j2.properties,修改日志目录,接下来在创建hive/logs,目录 ...
- hadoop 3.x Replication与Availability不一致
看下面的文字前先确保你的Replication值不大于你设置的虚拟机数量 如图,显示的副本数为3,但是实际可用的只有一台机器,查看了下hadoop003,hadoop004两台机器,果然没有存储数据, ...
- gradle命令学习
概述 命令学习比较枯燥,全部是例子~ gradle版本 假设你的本地gradle已经安装配置完成.没有安装配置的,可以参考 gradle安装 C:\Users\yueling.DANGDANG> ...
- Cocos2d-x 3.2 Lua演示样本 ActionTest(操作测试)
Cocos2d-x 3.2 Lua演示样本 ActionTest(操作测试) 2014年博文大赛,请投上您宝贵的一票:http://vote.blog.csdn.net/Article/Details ...
- [android]完美的解决方案ListView加载网络图片反弹问题
为什么 先说为什么有照片反弹. 使用convertView对ListView的每一个item优化,item的复用能够有效减少内存的占用.使ListView滑动更为流畅. 但会带来一个问题,当最顶部的i ...
- phpstudy2018升级MySQL5.5为5.7.24教程(图文)
原文: phpstudy2018升级MySQL5.5为5.7教程(图文) 一.MySQL官网下载MySQL5.7版本,我这里下载的是MySQL5.7.24. 二.直接到D:phpStudyPHPTut ...
- ASP.NET Core 基础教程 - ASP.NET Core 基础教程 - 简单教程,简单编程
原文:ASP.NET Core 基础教程 - ASP.NET Core 基础教程 - 简单教程,简单编程 ASP.NET Core 是对 ASP.NET 有重大意义的一次重新设计.本章节我们将介绍 A ...
- WPF使用DynamicDataDisplay.dll显示CPU及内存使用曲线
原文:WPF使用DynamicDataDisplay.dll显示CPU及内存使用曲线 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/wangshub ...