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 ...
随机推荐
- 【P084】立体图
Time Limit: 1 second Memory Limit: 50 MB [问题描述] 小渊是个聪明的孩子,他经常会给周围的小朋友们讲些自己认为有趣的内容.最近,他准备给小朋友们讲解立体图,请 ...
- cordova-plugin-file-transfer 监听到下载成功,找不到文件 - 简书
原文:cordova-plugin-file-transfer 监听到下载成功,找不到文件 - 简书 下载成功后找不到下载文件 function download(fileEntry, uri) { ...
- nginx 和 tomcat 生产环境配置 建议和方法
参考 以下内容: http://blog.csdn.net/lifetragedy/article/details/7708724 一. nginx参数调优 worker_processes 3; ...
- TensorFlow 实战(三)—— 实现常见公式
tf.reduce_mean (求向量的均值)等价于 1N∑i=1Nxi 1. 对权值矩阵进行 l2 正则 def variable_with_weight_loss(shape, stddev, w ...
- Java实现多文件压缩打包的方法
package com.biao.test; import java.io.File; import java.io.FileInputStream; import java.io.FileOutpu ...
- 在当前页获取父窗口中母版页中的服务器控件的ID
parent.document.getElementById("ctl00_ContentPlaceHolder1_txt_name").value=""; A ...
- jQuery多库共存处理$.noConflict()
如果我们需要同时使用jQuery和其他JavaScript库,我们可以使用 $.noConflict()把$的控制权交给其他库.旧引用的$ 被保存在jQuery的初始化; noConflict() 简 ...
- vs2008C1902数据库管理程序不匹配
打开一大早vs2008,有这么奇怪的错误, 删了dll正好.图. 版权声明:本文博主原创文章.博客,未经同意不得转载.
- 2-2 Consul注册注销流程
铺垫,创建健康检查方法,Consul服务器隔一段时间请求一下webapi里的一个方法,如果这个方法没有问题,则证明这个webapi还在正常工作,这个webapi提供的服务就存在.如果方法没有返回,或者 ...
- cocos2dx-3.1加入cocosStudio参考库 libCocosStudio
一个,创建好项目 两,在"解(项目名称)".选择现有项目 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvd2dzbHVja3k=/fon ...