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

查看:20
本文介绍了如何提高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.

解决这个问题的技巧 不要忘记小枝".
我在 DelphiLive 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;

希望这会有所帮助.

--jeroen

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

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