向表单添加表单和框架 [英] Adding forms and frames to packages

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

问题描述

我正在开发一套IDE注册的组件,其中大部分来自一个基本的TFrame类。还有包含在包中的这些组件调用的各种自定义对话窗体。我正在Delphi 2007中工作。



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



如果我添加新的,并且在项目中创建一个新的窗体或框架单元,它将显示为项目管理器中典型的嵌套双文件项目。如果将现有表单从项目组中的另一个项目拖动到有问题的BPL项目中,那么它也将显示出来。



看起来应该是一致的,我更喜欢这两个文件显示单位是框架或窗体。



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



* UPDATE * p>

从Alen的建议如下:



我尝试向表单单位添加{$ R * .dfm}并且在将DFM文件添加到我的BPL包/项目时,并没有强制显示DFM文件。将{$ R * .dfm}添加到项目文件本身(我不认为是你的意思,但是我以为我会尝试)也不起作用。这个技巧只适用于EXE项目吗?



可能(很可能)相关,试图用这个指令在这个地方建立起来:



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



Keping和丢弃相同的文件? ?






稍后:看起来这个重复资源问题可能与
这个。不确定,但至少在一个例子中都同时发生。

解决方案

Vegar在正确的轨道上。为了让项目经理显示.dfm节点,它需要知道一个form / frame / datamodule与pas文件相关联。它查看.dpk或.dpr文件中的{Form1}注释。如果在向项目添加文件时,IDE不会识别出与其关联的.dfm文件,请确保.pas文件中的{$ R * .dfm}指令清楚。因此,我不应该被埋在IFDEF中,或者由于文件中潜在的语法错误而被隐藏。 IDE使用此指令的存在来决定是否应尝试在设计器中打开.dfm。



IDE不仅仅认为如果有一个Unit1.pas和一个Unit1.dfm,他们真的应该在一起。考虑到你创建了一个新的单元,它被称为Unit1。现在你只删除了Unit1.pas,然后刚刚创建了一个新的单位,这个名字叫Unit1.pas。没有提到旧的,过时的Unit1.dfm在这个新的同名的Unit1.pas的磁盘上。如果IDE只是盲目地打开那个.dfm。


,这将是奇怪而令人困惑的

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.

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.

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?

* UPDATE *

From Alen's suggestion below:

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 Error] E2161 Warning: Duplicate resource: Type 10 (RCDATA), ID TTESTTREEVIEW; File E:\Projects\MyApp\Components\TTestTreeViewFrame.dfm resource kept; file E:\Projects\MyApp\Components\TTestTreeViewFrame.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 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.

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天全站免登陆