Using DXE2, I’ve written a form generator that creates both .pas and .dfm files. I am working on a routine that will allow me to modify different properties in the the dfm, such as Font.Height and TabOrder.
When I open a generated file in notepad, everything looks exactly as I expect it to. When I open it up in Delphi, the properties get changed! The thing that is so frustrating is that I am using a form originally designed in the Delphi IDE as my template. I don’t understand why Delphi won’t respect my simple changes…
For example, the original Font.Height is -11. I read in the dfm, change it to -17, and save it. In notepad, it shows the -17. When I open it in Delphi, it shows up as -21!
Any ideas/tips/suggestions would be greatly appreciated!
My guess is that you have a mismatch between the
PixelsPerInchon your machine and the value stored in the .dfm file. When Delphi reads the .dfm file it will scale any dimensions according to the ratio of the .dfm filePixelsPerInchand your machine’s currentPixelsPerInch.Typical values of
PixelsPerInchare 96dpi and 120dpi. Note that17*120/96 = 21.Now, as for
TabOrder, the IDE will always write out the form order in consecutive values. So, if you have any values missing in your .dfm file then the IDE will write out a different version of theTabOrdervalues.Note that you can’t get Delphi to leave your .dfm file alone. Once you make any modification to the design space, and save the form, Delphi will stream it out in its preferred format.
This is really an unavoidable consequence of the way .dfm files are handled. The IDE never edits .dfm files directly in the same way it does with your .pas files. Instead it reads the .dfm file in, creates the components defined on the form, and assigns their properties. When the .dfm file needs to be saved again, the components are asked to stream themselves out. So the underlying model that is holds the settings is a
TComponentinstance (often a form for example) owned by the IDE rather than the .dfm file.