Mega Code Archive

 
Categories / Delphi / Forms
 

.DFM Hacking, The Useful but Rarely Used Technique

Title: *.DFM Hacking, The Useful but Rarely Used Technique Question: Standard Operation Procedure for changing property value from a project with a lot of forms. Answer: Sometimes we change our mind about a property value of VCLs. The most common workaround for this is, open our forms one by one and change the property value. What if we have a lot of forms in our project. OK we can use OnCreate event for setting the property value at common ancestor forms. This works only when you have several common ancestor forms (base forms). What if you don't have a common ancestor forms (my deepest sympathy for you ^_^) or the property value already takes effect while loading. Don't worry you don't have to set them one by one from Object Inspector. Delphi Form File is your Delphi form that is serialized into a text file. It's very easy to understand the text file. You can edit the DFM files and save it. When you change your mode into View As Form you can see from Object Inspector that your changes already takes effect. OK here's my Standard Operation Procedure (SOP) for hacking DFM: 1. Backup your project first. I hate being cursed by you when you messed up your project ^_^. 2. Find a keyword for searching your property value. Inspect one form DFM first for the correct keyword (right click a form and choose View as Text). 4. Close all form in your project but leave your project open. 5. From Windows Explorer right click your project folder and choose find (F3). Select Advanced tab from Find Dialog. Choose Delphi Form as the file type and enter your keyword and click Find Now (Enter). Sort the file as you wish. 6. Highlight the first file and hit Enter. Explorer will open this file on your already opened project. Maximize the source code editor window. Hit CTRL+F and enter your keyword. Change the property value as you wish and hit F3 for changing next property value until no more keyword found. Hit CTRL+S for saving your changes. Don't close this file since you will need to maximize source code editor for the next DFM. 7. Hit ALT+TAB for switching back to Find Dialog and hit DOWN ARROW for next DFM and hit ENTER. 8. Hit F3 for changing property value until no more keyword found. Hit CTRL+F4 for closing your DFM. And choose Save (ENTER) for Close Dialog. Repeat to step 7 until all DFM processed. 9. Try to build your project, when something goes wrong, use your backup for recovering your damaged DFM. 10. OK you have done a good job and you deserve a 10 minutes coffee break ^_^. OK good luck and let me know if you have build an automated parser for doing this.