Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/IDE/Code Editor/Code Formatter    [ Add a report in this area ]  
Report #:  87861   Status: Closed
Code Formatter in DPR file corrupting form management
Project:  Delphi Build #:  14.0.3615
Version:    14.0 Submitted By:   Taylor Denison
Report Type:  Crash / Data loss / Total failure Date Reported:  9/7/2010 5:27:36 PM
Severity:    Critical / Show Stopper Last Updated: 9/9/2010 6:23:39 PM
Platform:    All platforms Internal Tracking #:  
Resolution: Duplicate (Resolution Comments) Resolved in Build: : None
Duplicate of:  78831
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: None
If you're editing the .dpr file and hit the nifty code formatter, it modifies the .dpr file in a way that makes the IDE think that your forms have spaces before and after the class names inside of your units with related forms.

Because the IDE thinks there should be spaces, when it tries to find or create those forms, it puts a space inbetween the 'T' and the 'frmMain' (for example), causing it to try to create 'T frmMain ' instead of just 'TfrmMain' -- whereas 'T frmMain ' obviously doesn't exist or work with class/variable naming.

Specific issues caused:
1. Can't pick a Main Form in the project options > Forms section, as you won't be able to compile your .dpr due to the non-existant 'space-filled' classes
2. You can't use the project options > Forms section to set up your auto-create forms, you have to do it yourself in the DPR
3. If you're using a unit that uses a frame, it won't be able to find the frame (presumably it's trying to find a 'T someframe ' and fails, and your only options of 'Ignore' or 'Cancel' cause you to either have the frame removed entirely from the form, or you to not be able to edit that unit until the bug has been fixed(or maybe with notepad, I didn't try)

This is caused from the formatter seeing the 'comments' above that state those names and putting spaces after and before the curly braces that initiate and end the comments, respectively.  Apparently these aren't actually comments, they're actually used by the IDE to determine class names, so the spaces ruin everything.

In other words, the inside of the curly braces needs to be Trim()'d (in delphi speak), or the code formatter needs to somehow be told that they aren't actually comments.

Or more reasonably, locate that information in a way that doesn't give the coder the impression that they can modify those comments to be more meaningful(which should similarly cause the same issues)
Steps to Reproduce:

Make a project with a main form in it, and to get the full effect make a frame then use the frame inside that form (or inside another form).  Save your project, compile, run, it'll do just fine of course.

Now go to the project's DPR file in the code editor and use the code formatter on it (ctrl+d), you'll see that spaces are inserted before and after the braces above.

Save the project, close the IDE

Reopen the IDE, it likely will open directly to your DPR instead of your main form, (the DPR should still have those spaces) and head to Project > Options > Forms.  Main form will likely be unset, and the list on the right will have a space visible on the left-hand side.  Try putting one of those forms back to the auto-create list (it will automatically be set as the main form).  Now try to compile.

You'll be brought back to your DPR file to see that it tried to autocreate a 'T myform ' and says you have syntax errors, which keeps you from compiling.  You can remove those spaces yourself, but as you'll see back in Project > Options > Forms, it will unset your main form and, while that form will be on the left side, it will not be recognized as an eligible 'main form'

Now, if you used a form with a frame, try opening that file for modification using the project manager, and you should be told that the frame could not be found, and you can either remove all references to the frame or just deal with not being able to edit that file anymore.
Go to your DPR file, remove all the spaces inside the curly braces(that is, just the ones immediately inside of the braces, as if you yourself are performing a Trim() function on the inside of the brackets).  Save, close the IDE, reopen, and you should be fine.  Just avoid that code formatter button from here on out when working with non-pas files!

Tomohiro Takahashi at 9/8/2010 6:23:42 AM -
> Now go to the project's DPR file in the code editor and use the code formatter on it (ctrl+d),
> you'll see that spaces are inserted before and after the braces above.
Is your issue same as QC#78831, QC#86968 ?

Tomohiro Takahashi at 9/9/2010 6:26:43 PM -
Does your issue still occur with Delphi XE?
If possible, could you retest the issue with Delphi XE(Trial Edition)?

Server Response from: ETNACODE01