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的博客)的更多相关文章

  1. 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 ...

  2. Getting Text Metrics in Firemonkey(delphiscience的博客)

    Firemonkey’s abstract TCanvas class has been providing the dimensions of the bounding rectangle of s ...

  3. Delphi GDI或图像处理的博客

    http://blog.csdn.net/w1028489713/article/category/1918251

  4. delphi Firemonkey ListBoxItem自绘

    delphi Firemonkey ListBoxItem自绘 ListBoxItem1的事件ListBoxItem1Paint procedure TForm1.ListBoxItem1Paint( ...

  5. delphi Firemonkey ListView 使用参考

    delphi Firemonkey ListView 使用参考 Tokyo版本 http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Customizin ...

  6. Delphi Firemonkey Button ImageList

    Delphi Firemonkey Button ImageList 按钮图标 在上面 界面上,选择Button,放个ImageList控件,添加图标到ImageList. 然后关联Button和Im ...

  7. 自定义经纬度索引(非RTree、Morton Code[z order curve]、Geohash的方式)

    自定义经纬度索引(非RTree.Morton Code[z order curve].Geohash的方式) Custom Indexing for Latitude-Longitude Data 网 ...

  8. Color gradient in Delphi FireMonkey

    Introduction to color gradients in Delphi FireMonkey. Video This video covers the basics of color gr ...

  9. 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 ...

随机推荐

  1. Qt多线程和GUI界面假死(run()是线程的入口,就像main()对于应用程序的作用。分析QThread::exec函数的源码,旧的QMutexLocker模式其实很好用,挡住别人进入抢占资源,可照抄)good

    QThread的常见特性: run()是线程的入口,就像main()对于应用程序的作用.QThread中对run()的默认实现调用了exec(),从而创建一个QEventLoop对象,由其处理该线程事 ...

  2. 【BZOJ 1025】[SCOI2009]游戏

    [题目链接]:http://www.lydsy.com/JudgeOnline/problem.php?id=1025 [题意] [题解] 每一个对应关系,里面其实都会生成大小不一的几个环. 每一个环 ...

  3. hive 分区表与数据产生关联的三种方式

    所谓关联,可以理解为能够使用select查询到 1.load 这是最常用的一种方式 load data [local] inpath "数据路径" into table table ...

  4. 《大话操作系统——扎实project实践派》(8.2)(除了指令集.完)

  5. hadoop 3.x 服役 | 退役数据节点

    在服役前要配置好新增主机的环境变量,ssh等信息,个人环境介绍 hadoop002(namenode),hadoop003(resourcemanager),hadoop004(secondaryna ...

  6. WPF 通过位处理合并图片

    原文:WPF 通过位处理合并图片 本文告诉大家,在使用 WPF 合并两张图片的处理,可以使用像素之间的与或和异或的方式,对三个颜色的通道进行处理. 先给大家看一下软件的界面 这就是通过将左边的两张图片 ...

  7. GammaRay is a tool to poke around in a Qt-application(确实很多功能)

    GammaRay is a tool to poke around in a Qt-application and also to manipulate the application to some ...

  8. 字符串、对象、数组操作方法、json方法

    1.字符串操作方法                 1.charAt               *     作用              *         通过索引找字符             ...

  9. 将枚举转成SelectListItem

    代码如下: /// <summary> /// 将一个枚举转化成一个List<SelectListItem> /// </summary> /// <type ...

  10. Android Ant 和 Gradle 包装工艺和效率控制

    一个.Ant 包:(下载ant.配置环境变量不说) 1.进入命令行模式,并切换到项目文件夹,运行例如以下命令为ADT创建的项目加入ant build支持: android update project ...