views:

536

answers:

3

I thought there was something in GExperts to do this, but I can't see it if there is.

I have to change the SCALED property (from the default of TRUE to FALSE) in each form in a project that contains about 100 different forms. Because the default value of SCALED is TRUE, it doesn't actually appear as a line in the .DFM file (when viewing as text), so there isn't anything I can 'get' at with GREP (etc).

Can anyone suggest a quick way of setting this property in all these forms? The forms are subclasses of various different classes and I really don't want to do make some kind of intermediate TForm descendant which overrides the SCALED property - partly because I tried (briefly) to do this and discovered that setting the SCALED property to be false after the inherited create made no difference to the form, and setting it before the inherited create caused an exception. :-)

Anyone got any suggestions? I really want to avoid opening all those forms one by one if I can help it, if only because I'm bound to miss one!

+5  A: 

I would recommend changing all your forms to descend from a common ancestor. Then in the future you can just change the base class and it will fix it everywhere.

Generally I prefer to always use a custom descendant class over a stock one that I will be using frequently for this specific reason.

Jim McKeeth
This is good advice for new projects, but maybe overkill as change in a mature project.
mghie
Thanks Jim. That's probably the right thing to do in the long run but obviously it's a pain to actually do in the short term! :-)
robsoft
You can do it in mature project using a global search and replace. The dividends are great.
Jim McKeeth
+5  A: 

Provided that all your DFM files are not binary, but text (which is a good idea, unless you need to be compatible with Delphi 4 or earlier) you can of course use grep / sed / awk. The format of the DFM is not fixed, and instead of

  OldCreateOrder = False
  Scaled = False

it could also contain

  OldCreateOrder = False Scaled = False

So you can grep for one other property that only TForm has, which is set in all of your forms to a value that is stored in the DFM (OldCreateOrder would be a candidate), and replace the lines with another line containing two properties.

The format will be corrected the next time you save that form in the IDE.

Edit:

If your forms are binary, then use the convert.exe tool in Delphi bin directory (use full path, as there is another convert.exe in Windows) to convert the DFM to text, then add the missing property, then (optionally) convert the DFM back to binary. And if you are unhappy about the weird format - convert the DFM from text to binary and back to text, this will give you a correctly formatted text DFM file. All of this is easily scriptable.

mghie
Thanks mghie. The forms are text, and this approach is what I was trying to do. However, because the SCALED property is true by default, it's not there in the .DFM file to begin with. This is one time when it would have been helpful for properties left at default value to be stored in the stream!
robsoft
I just understood what you were actually getting at! I can do the 'two line' trick to ADD this assignment to all of the forms even though the property isn't currently there. I'm ADDING a line, not search/replacing an existing property. Brilliant! I'll try this now.
robsoft
I guess you did not understand. I know that Scaled is not there, but you can programmatically replace "OldCreateOrder = False" with "OldCreateOrder = False Scaled = False" and then it is there. Maybe I did not make myself clear enough, how can I improve my answer?
mghie
That worked a treat, using GExperts. Thanks mghie, you're a star!
robsoft
No need to improve your answer mghie, I was being thick! Thanks again, your suggestion worked perfectly.
robsoft
+1  A: 

Yes, GExpert includes a 'Set Component Properties' expert. It has a 'simulation' mode to see what it will do. This tool is useful to deactivate datasets or database connections before you compile your applications.

mjustin