Is there a Delphi option to 'lock' the design (layout) of a form against accidental changes?
Asked Answered
M

4

10

After years of Delphi development I now have hundreds of forms shared throughout our Applications. Compilation ranges from Delphi 7 through to XE, thus one form might be opened in any IDE. The well-known Explicitxxx property addition after Delphi 7 has solutions to avoid a form accidentally acquiring properties that earlier compilers can't process (e.g Andreas's DDevExtensions) but I'd like a more positive 'switch' that prevented Delphi from making or saving any form modifications at all. Period.

Of course you could use the read-only flag, and a version control system provides additional means particulay of seeing that such a modification has occured. What I'd really like though is a {$LockDFM} switch that I could put in the form's unit, or a context menu option when viewing the form layout.

Can anyone think of a neat way of achieving this?

Thanks

Marvelous answered 30/3, 2011 at 13:27 Comment(1)
I'm not aware of anything. I rely on my VCS and merge program to deal with this. Plus Andreas's wonderful add-ons. Same as you then!Quipu
O
9

The only thing I can think of (other than the read-only/VCS options you mentioned) is the Edit menu's Lock Controls option. This sets a flag that prevents controls from being moved around. I'm not sure how much good it would actually do, as I've never tried it; I just know it's there.

Onset answered 30/3, 2011 at 13:32 Comment(2)
Sadly lock controls does not work for this purpose. When you open a form, you have to disable/enable lock controls again for it to work on that form but at that point the damage has already been done. (QC82764)Litmus
@PetriW: Thanks. I didn't know about that QC report. As I mentioned, I've never used it.Onset
G
3

Helo

I am pretty sure that Delphi has no such a thing. I have been searching for a solution to this problem as well.

But, theres one thing you can do: You can write your own Delphi addon using OTA (Open Tools API). I know that there are a few classes which are able to notify you when something are about to be saved. You can intercept this event and decide if you wanna save it (in your case, if it is a DFM).

BTW, if you have plans to do such component, tell me. :)

EDIT:

I have found a piece of code that may help you. Extracted from http://www.gexperts.org/otafaq.html

  TMyFormNotifier = class(TNotifierObject, IOTANotifier, IOTAFormNotifier)
  protected
     procedure FormActivated;
     procedure FormSaving;
     procedure ComponentRenamed(ComponentHandle: TOTAHandle; const OldName, NewName: string);
  end;
Grimsley answered 31/3, 2011 at 3:2 Comment(0)
M
1

In design time there is Edit->Lock Control.

LE: this is only for resizing/repositioning the controls on the forms. Concerning the ObjectInspector I don't know if there is anything that can 'lock' the values set there(so the developer can not change them).

Mammet answered 30/3, 2011 at 13:37 Comment(1)
Yes, I need something to stop Delphi from 'upgrading' the DFM structure in any way at all.Marvelous
T
1

Basically, no. Aside from the f'ing (pardon my french) explicit size and position properties which IMO never should have been in the .dfm, there are some third party components will change stuff just by you viewing the form. F.x. TMS components will update a version number even if you didn't change a thing since the previous version of their components.

Tague answered 30/11, 2014 at 12:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.