在Delphi中如何使用或解决视觉形式继承问题? [英] How do I use or resolve issues with visual form inheritance in Delphi?

查看:151
本文介绍了在Delphi中如何使用或解决视觉形式继承问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在Delphi 7中开发一个项目,希望让表单从其他表单继承组件。我能够得到这个工作,但遇到了以下问题(我将要发布解决方案,希望将来可以帮助别人):

I've been working on a project in Delphi 7 where I wanted to have forms inherit components from other forms. I was able to get this working, but came across the following issues (and I'm going to post the solutions to hopefully help others in the future):


  1. 在表单的.pas文件中,我将更改表单继承自其他表单,但不能从祖先格式获取组件。

  2. 对于某些后代形式,在设计时打开表单时,我会收到以下错误消息:创建表单:未找到TAncestorForm的祖先错误。我必须首先手动打开祖先形式,然后我可以打开后代的形式。


推荐答案

首先,对于那些不知道如何在视觉上继承形式的人,您可以像往常一样创建祖先形式。然后转到文件>新建>其他。选择具有当前项目名称的选项卡,然后选择要继承的表单。如果要从不属于当前项目的表单继承,请打开该表单,右键单击该表单,然后选择添加到存储库。然后,您将可以转到文件>新建>其他,然后从相应的选项卡中选择该表单。

First, for those who don't know how to inherit a form visually, you create the ancestor form as usual. Then go to File > New > Other. Select the tab with the name of the current project, and choose the form you want to inherit from. If you want to inherit from a form that's not part of the current project, open that form, right click it, and choose Add to Repository. Then you will be able to go to File > New > Other and select that form from the appropriate tab.

鉴于此,我遇到问题,因为某些后代形式已经创建,所以我不能按照上面的过程。此外,我从Delphi创建的标准代码中对表单做了一些更改。我可以使用以下准则解决所有视觉形式继承的问题:

Given that, I came across issues because some of the descendant forms were already created, so I couldn't follow the process above. Also, I made some changes to forms from the standard code Delphi creates. I was able to resolve all issues with visual form inheritance using the following guidelines:


  • 后代表单的.pas文件必须具有类继承自正确的祖先类,例如:

    类型TMyForm = class(TAncestorForm)

  • 第一个后代表格的.dfm中的行必须具有继承而不是对象,例如:

    继承MyForm:TMyForm

  • 编辑:双重检查后,不需要以下内容:祖先形式的.pas文件必须具有Delphi创建的标准全局变量,例如:

    var AncestorForm:TAncestorForm;

  • 项目的.dpr文件中的部分使用该单元的文件后,必须具有与注释相同的全局变量名称,例如:

    unAncestor in'unAncestor.pas'{AncestorForm}

  • The .pas file of the descendant form must have the form's class inherit from the correct ancestor class, e.g.:
    type TMyForm = class(TAncestorForm)
  • The first line in the .dfm of the descendant form must have the word inherited instead of object, e.g.:
    inherited MyForm: TMyForm
  • After double checking, the following is NOT required: The .pas file of the ancestor form must have the standard global variable that Delphi creates, e.g.:
    var AncestorForm: TAncestorForm;
  • The uses section of the .dpr file of the project must have that same global variable as a comment after the unit's file name, e.g.:
    unAncestor in 'unAncestor.pas' {AncestorForm}

注意/提示:


  • 如果您需要,祖代表和后代表都被允许为非自动创建在项目>选项>表单>自动创建表单中)。

  • 要将后代表单上的属性还原为祖先表单的值,请右键单击对象检查器中的属性,选择还原为继承。

  • 要将组件的所有属性值还原为祖先的值,请右键单击该组件,然后选择还原为继承。

这篇关于在Delphi中如何使用或解决视觉形式继承问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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