views:

512

answers:

3

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.

+2  A: 

If you take a look at the project source for the package, you will find a difference in the Contains-section:

contains
  Unit2 in 'unit2.pas',
  Unit1 in 'Unit1.pas' {Form1};

Unit2 will show as a single unit, and unit1 will show as a unit with a form. As you can see, unit1 has a {Form1} comment that unit2 lacks.

I do not know if it's possible to add an existing unit so that this comment is automatically generated.

Vegar
Helpful!! Thanks. : )
Jamo
+6  A: 

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.

Allen Bauer
Allen - Great to see you and Nick here. Thanks for the suggestion and clarification. I tried this but ran into problems (see update above).
Jamo
Make sure there isn't already a {$R *.dfm} in the unit first. From the error you got, that looks to be the case.
Allen Bauer
i.e. you're thinking thinking I probably have that directive it both the form's unit, and the project file? Is that what you mean?
Jamo
...or, that it's in the same form unit twice? (Thanks again for your help!)
Jamo
A: 

Another reason for anyone else that is looking for another solution is when you rename pas file close all files and reopen. The previous version will reopen & must be removed with previously named added to project