将表单和框架添加到包中 [英] Adding forms and frames to packages

查看:14
本文介绍了将表单和框架添加到包中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 IDE 注册组件包,其中大部分是从 TFrame 基类派生的.包中还包含由这些组件调用的各种自定义对话框表单.我在 Delphi 2007 工作.

I am developing a package of IDE-registered components, most of which are derived from a base TFrame class. There are also various custom dialog forms that are called by these components, included in the package. I'm working in Delphi 2007.

我注意到,有时通常具有关联 DFM 文件的框架和表单单元并不总是在其下方显示 DFM 文件(可通过小 [+] 树视图节点扩展器访问).如果我添加一个现有的基于表单的 PAS 文件,例如,通过右键单击 BPL 项目(在项目管理器中)-> 添加,它不会在列表中显示 DFM 文件.

I'm noticing that sometimes frame and form units, which normally have an associated DFM file, do not always show the DFM file "underneath" (accessible via the little [+] treeview node expander) underneath them. If I add an existing form-based PAS file, for instance, via right-clicking on the BPL project (in the Project Manager) -> Add, it doesn't show the DFM file in the listing.

但是,如果我添加新的并在项目中创建一个新的表单或框架单元,它会在项目管理器中显示为典型的嵌套两个文件项.如果我将现有表单从项目组中的另一个项目拖到该 BPL 项目中,它也会显示这种方式.

If I Add New, though, and create a new form or frame unit in the project, it shows as the typical nested two-file item in the Project Manager. It also shows that way if I drag an existing form from another project in the Project Group to this BPL project in question.

似乎这应该是一致的,我更喜欢两个文件显示单位是框架或表格时.

Seems like this should be consistent, and I prefer both files showing when the unit is a Frame or Form.

这是否表明项目文件中有问题?我是否错误地将现有表单/框架添加到此包中?如果是这样,我应该如何添加现有的表单/框架单元,以便两个文件都显示在项目管理器列表中?

Is this indicative of something wrong in the project file? Am I adding existing forms/frames to this package incorrectly? If so, how should I add existing form/frame units so that both files show in the Project Manager listing?

* 更新 *

以下来自 Alen 的建议:

From Alen's suggestion below:

我尝试将 {$R *.dfm} 指令添加到表单的单元中,并且在将 DFM 文件添加到我的 BPL 包/项目时它不会强制显示它.将 {$R *.dfm} 添加到项目文件本身(我认为这不是您的意思,但我想我会尝试)也不起作用.这种技术是否只适用于 EXE 项目?

I tried adding the {$R *.dfm} directive to the form's unit, and it did not force the DFM file to show up when adding it to my BPL package/project. Adding {$R *.dfm} to the project file itself (which I don't think is what you meant, but I thought I'd try it) didn't work either. Does this technique only work with EXE projects?

可能(可能)相关,尝试在某些地方使用该指令进行构建给了我这个:

Possibly (likely) related, trying to build with that directive in places gives me this:

[DCC 错误] E2161 警告:重复资源:类型 10 (RCDATA),ID TTESTTREEVIEW;文件 E:ProjectsMyAppComponentsTTestTreeViewFrame.dfm 资源保留;文件E:ProjectsMyAppComponentsTTestTreeViewFrame.dfm 资源被丢弃.

[DCC Error] E2161 Warning: Duplicate resource: Type 10 (RCDATA), ID TTESTTREEVIEW; File E:ProjectsMyAppComponentsTTestTreeViewFrame.dfm resource kept; file E:ProjectsMyAppComponentsTTestTreeViewFrame.dfm resource discarded.

保留"和丢弃"同一个文件??

"Keping" and "discarding" the same file??

稍后:看起来这个重复资源"问题可能与这个.不确定,但至少在一种情况下,两者同时发生.

Later: It looks like this "duplicate resource" issue MIGHT be related to this. Not certain, but at least in one instance both happened simultaneously.

推荐答案

Vegar 是在正确的轨道上.为了让项目经理显示 .dfm 节点,它需要知道一个 form/frame/datamodule 与 pas 文件相关联.它会查看 .dpk 或 .dpr 文件中的 {Form1} 注释以获取此信息.如果在将文件添加到项目时,IDE 无法识别出与之关联的 .dfm,请确保 .pas 文件具有明确的 {$R *.dfm} 指令.这样一来,我不应该被 IFDEF 所掩盖,或者被文件中潜在的语法错误所掩盖.IDE 使用此指令的存在来决定是否应尝试在设计器中打开 .dfm.

Vegar is on the right track. In order for the project manager to display the .dfm node, it needs to know that a form/frame/datamodule is associated with the pas file. It looks at the {Form1} comment in the .dpk or .dpr file for this information. If, when adding a file to the project, the IDE doesn't recognize that there is a .dfm associated with it, make sure the .pas file has the {$R *.dfm} directive in the clear. By that, I should not be buried in an IFDEF or otherwise obscured by potential syntax errors in the file. The IDE uses the presence of this directive to decide whether or not it should try and open the .dfm in the designer.

IDE 不会理所当然地认为,如果有 Unit1.pas 和 Unit1.dfm,它们确实应该在一起.假设您创建了一个新的表单单元,它被称为 Unit1.现在您只删除了 Unit1.pas,然后创建了一个名为 Unit1.pas 的新单元.这个新的、同名的 Unit1.pas 中没有对磁盘上旧的、陈旧的 Unit1.dfm 的引用.如果 IDE 只是盲目地打开那个 .dfm,那会很奇怪和令人困惑.

The IDE doesn't just take for granted that if there is a Unit1.pas and a Unit1.dfm, that they are really supposed to be together. Consider that you created a new form unit and it was called Unit1. Now you deleted just the Unit1.pas and then just went and created a new unit which would be given the name Unit1.pas. There is no reference to the old, stale Unit1.dfm out there on the disk from this new, same-base-named, Unit1.pas. It would be strange and confusing if the IDE were to just blindly open that .dfm.

这篇关于将表单和框架添加到包中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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