如何提高 Delphi Frames 的使用率 [英] How to improve the use of Delphi Frames

查看:12
本文介绍了如何提高 Delphi Frames 的使用率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

多年来我一直在 Delphi 中使用框架,它们是 VCL 最强大的功能之一,但标准使用它们似乎存在一些风险,例如:

I've used frames in Delphi for years, and they are one of the most powerful features of the VCL, but standard use of them seems to have some risk such as:

  1. 很容易意外移动或编辑框架主窗体上的框架子组件,而不会意识到您正在对框架进行调整" - 我知道这不会影响原始框架代码,但通常不会你想要什么.

  1. It's easy to accidentally move or edit the frame sub-components on a frame's host form without realising that you are 'tweaking' with the frame - I know this does not affect the original frame code, but it's generally not what you would want.

在使用框架时,您仍会看到其子组件以进行可视化编辑,即使该框架已使用多年且不应触摸.

When working with the frame you are still exposed to its sub-components for visual editing, even when that frame is years old and should not be touched.

所以我开始思考......

So I got to thinking....

  1. 有没有办法对组件进行分组"以使它们的位置被锁定"?这对于完成的表格和框架都很有用.通常,其他开发人员向我返回的代码只是表单边界发生了变化,甚至他们并不打算进行任何更改.

  1. Is there a way of 'grouping' components such that their positions are 'locked'? This would be useful for finished forms as well as frames. Often other developers return code to me where only the form bounds have changed and even they did not intend any change.

有什么方法可以将框架及其组件转换为单个 Delphi 组件?如果是这样,框架内部将完全隐藏,其可用性将进一步提高.

Is there any way of turning a frame and its components into a single Delphi component? If so, the frame internals would be completely hidden and its useability would increase further.

我对任何想法都感兴趣...

I'm interested in any thoughts...

布赖恩.

推荐答案

将你的框架注册为组件解决了 1. 和 2.:

Registering your frames as a component solves both 1. and 2.:

  1. 当您将框架控件放在窗体或其他框架上时,框架上的组件会被锁定
  2. 您将获得一个可以直观设计的组件(实际上是:控件)

但是:有几个问题(可以解决,见文章链接),其中最重要的是这个:

But: there are a few catches (which can be solved, see article link), of which the most important is this one:

当您将组件放在框架上,然后将该框架作为组件放在 Delphi 表单或框架上时,这些组件在结构窗格中可见.

问题是因为它们在结构窗格中可见,您可以删除它们,导致访问冲突.

The problem is that because they are visible in the structure pane, you can delete them, causing access violations.

解决这个问题的诀窍是 不要忘记小枝".
我从 Ray KonopkaDelphiLive 2009.

The trick to solve this to not forget the 'sprig'.
I learned that valuable lesson from Ray Konopka during DelphiLive 2009.

由于课程非常有价值,我写了一个 博客文章详细描述了它.

Since the lesson is so valuable, I wrote a blog post on it that describes it in detail.

最重要的部分是这段代码(更多细节在博文中):

The essential portion is this little piece of code (more details in the blog post):

procedure RegisterFramesAsComponents(const Page: string; const FrameClasses: array of TFrameClass);
var
  FrameClass: TFrameClass;
begin
  for FrameClass in FrameClasses do
  begin
    RegisterComponents(Page, [FrameClass]);
    RegisterSprigType(FrameClass, TComponentSprig);
  end;
end;

希望这会有所帮助.

--杰罗恩

这篇关于如何提高 Delphi Frames 的使用率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆