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. 【codeforces 787C】Berzerk

    [题目链接]:http://codeforces.com/contest/787/problem/C [题意] 给你怪物一开始所在的位置; 然后两人轮流操作; 可以选择让这个怪物前进自己的集合里面所拥 ...

  2. scala 伴生对象与伴生类

    package cn.scala_base.oop.scalaobject import java.security.cert.Extension /** * object的构造器必须是无参的,且且构 ...

  3. Enhancing network controls in mandatory access control computing environments

    A Mandatory Access Control (MAC) aware firewall includes an extended rule set for MAC attributes, su ...

  4. WM_NOTIFY消息流程实例分析

    我们以CListCtrl控件为例来分析WM_NOTIFY消息. CListCtrl控件在Report样式下会包含CHeaderCtrl标头控件,即CHeaderCtrl标头控件为CListCtrl控件 ...

  5. 推荐一些C#相关的网站和书籍

    1.http://msdn.microsoft.com/zh-CN/ 微软的官方网站,C#程序员必去的地方.那里有API开发文档,还有各种代码.资源下载. 2.http://social.msdn.m ...

  6. Python中 如何将一个字符串分成一个个字符

    其实   一个字符串  实质也是 一个列表 就很简单了: a = ' for item in a: print(item) 打印结果: 121512 如果进而要统计字符出现的次数 , 那就很简单了.

  7. Android TV开发中所有的遥控器按键监听及注意事项,新增home键监听

    原文:Android TV开发中所有的遥控器按键监听及注意事项,新增home键监听 简单记录下android 盒子开发遥控器的监听 ,希望能帮到新入门的朋友们 不多说,直接贴代码 public cla ...

  8. python实现简易采集爬虫

    #!/usr/bin/python #-*-coding:utf-8-*- # 简易采集爬虫 # 1.采集Yahoo!Answers,parseData函数修改一下,可以采集任何网站 # 2.需要sq ...

  9. js div的显示和隐藏

    <head>    <title></title>    <style type="text/css">        div    ...

  10. SQLite 的版本问题

    原文:SQLite 的版本问题 在SQLite官方网站上的下载包真可以看花眼.不同的.net版本,还有不同的平台,开发和发布时需要加以注意. 在网上搜了搜,早有人注意到了. 关于在.Net开发中使用S ...