Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quick way to change a property on many forms in a Delphi project?

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!

like image 482
robsoft Avatar asked Jan 13 '09 22:01

robsoft


People also ask

How do I change main form in Delphi?

you can change the main form with Pointer((@Application. MainForm)^) := Form2; .

How do I show another form in Delphi?

Start a new project, and add one additional form (Delphi IDE Main menu: File -> New -> Form). This new form will have a 'Form2' name. Next add a TButton (Name: 'Button1') to the main form (Form1), double-click the new button and enter the following code: procedure TForm1.

What is a form in Delphi?

Form. Form objects are the basic building blocks of a Delphi application, the actual windows with which a user interacts when they run the application. Forms have their own properties, events, and methods with which you can control their appearance and behavior.


2 Answers

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.

like image 174
Jim McKeeth Avatar answered Sep 28 '22 08:09

Jim McKeeth


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.

like image 27
mghie Avatar answered Sep 28 '22 08:09

mghie