Delphi - Why does ExplicitWidth and ExplicitHeight keep appearing in .DFM files and what is it?
Asked Answered
S

4

43

We've noticed that when checking in updates, our .DFM files have added ExplicitWidth and ExplicitHeight properties - but we don't know why.

My questions are:

  • What are these properties for?
  • Why are they automatically added by Delphi?

Below is an example showing the added ExplicitWidth property:

object Splitter2: TcxSplitter
    Left = 0
    Top = 292
    Width = 566
    Height = 8
    Cursor = crVSplit
    HotZoneClassName = 'TcxXPTaskBarStyle'
    AlignSplitter = salBottom
    Control = BottomPanel
    Color = clBtnFace
    ExplicitWidth = 8
end
Sloven answered 19/3, 2010 at 11:7 Comment(5)
What does the Delphi documentation say ? :PHesychast
Are you seriously suggesting I RTFM? Now where's the fun in that? And I should add I'm using Delphi 2007 so I'm still waiting for the Help to load. I thought it would be quicker to ask on Stack Overflow!Sloven
@Mjustin, the help says this: ExplicitWidth is a read only property used internally by Delphi. Use Width in applications, thereby allowing read and write access. docwiki.embarcadero.com/VCL/en/Controls.TControl.ExplicitWidthNarcho
It so happens I did RTFM. All I got was the following: "This is ExplicitWidth, a member of class TControl." So thanks Rob. :)Ackack
all too often RTFM is an exercise in deciphering a vague, poorly written manual. Large companies farm this out to China so you often have a Chinese person, who knows very little English, typing up these manuals. I came here on a search for same problem. I use C++ Builder in the office and at home office and when I copy code back and forth, this happens to me too. I don't change the achors. One IDE puts them in and the other takes them out.Occasionally
A
32

From Googling....

Original article can be found here.

The Explicit properties remember the previous bounds of a control before the Align or Anchor properties are changed from their defaults.

The only time the Explicit properties are not written is when the Align property is set back to its default value of alNone.

This is when the Explicit properties are actually used by the control to reset its bounds to what it was previously.

Argenteuil answered 19/3, 2010 at 12:6 Comment(4)
They're the dimensions that you explicitly gave them, as opposed to the dimensions that they acquired implicitly due to alignment or anchoring. They're not necessarily the original dimensions, which you might have changed between the time you created the control and the time you set its alignment.Narcho
This sounds plausible, but it isn't what actually happens: In my experience the Delphi IDE switches between storing the same values in Left/Right/Width/Height an their ExplicitXxx counterparts every time the form gets written to the .dfm. The same applies to the ItemHeight property of a TComboBox which changes between 0 and 13 and back all the time. It gets quite annoying when my source control wants to post changes to the .dfm all the time when nothing actually has changed.Medusa
@Medusa many Delphi versions exhibit the behaviour you mention. It is irritating as it clutters the diffs in version control history.Legibility
Yes, the new Explicit* properties are automatically being written regardless of whether or not I have changed the Align or Anchor property. It contains Explict* = 0, and the version control history now shows meaningless changes. This is exactly the kind of thing that makes using Embarcadero annoying.Quarantine
S
40

With DDevExtensions you can disable storing these properties in the dfm:
http://andy.jgknet.de/blog/?page_id=10

Adds Explicit* property remover to keep DFM files compatible to older Delphi versions

Stockish answered 19/3, 2010 at 12:12 Comment(4)
+1. I don't use it for compatibilty reasons but just to keep my DFMs smaller and the source control diffs less cluttered.Englacial
I like this, since like Ulrich, it removes it from bugging us on source code updates. Wish I could split the answer between both this and JamesB's answer!Sloven
Thing is unless everyone who'll edit your dfm has DDevExtensions installed too, and the option turned on, you'll end up with more differences every time they save the file.Hokkaido
Perfect solution. Extension moved to idefixpack.de/blog/ide-tools/ddevextensionsRothenberg
A
32

From Googling....

Original article can be found here.

The Explicit properties remember the previous bounds of a control before the Align or Anchor properties are changed from their defaults.

The only time the Explicit properties are not written is when the Align property is set back to its default value of alNone.

This is when the Explicit properties are actually used by the control to reset its bounds to what it was previously.

Argenteuil answered 19/3, 2010 at 12:6 Comment(4)
They're the dimensions that you explicitly gave them, as opposed to the dimensions that they acquired implicitly due to alignment or anchoring. They're not necessarily the original dimensions, which you might have changed between the time you created the control and the time you set its alignment.Narcho
This sounds plausible, but it isn't what actually happens: In my experience the Delphi IDE switches between storing the same values in Left/Right/Width/Height an their ExplicitXxx counterparts every time the form gets written to the .dfm. The same applies to the ItemHeight property of a TComboBox which changes between 0 and 13 and back all the time. It gets quite annoying when my source control wants to post changes to the .dfm all the time when nothing actually has changed.Medusa
@Medusa many Delphi versions exhibit the behaviour you mention. It is irritating as it clutters the diffs in version control history.Legibility
Yes, the new Explicit* properties are automatically being written regardless of whether or not I have changed the Align or Anchor property. It contains Explict* = 0, and the version control history now shows meaningless changes. This is exactly the kind of thing that makes using Embarcadero annoying.Quarantine
C
0

Delphi adds value of published properties to DFM file only when its value different from default.

For example:

property ExplicitWidth: Integer read FExplicitWidth write FExplicitWidth default 1;

If ExplicitWidth value is not 1 then it will be written to the DFM. When the "default" is not defined then any value will be written to the DFM.

TcxSplitter is not standard Delphi component, you'd better ask its author about the purpose of the properties.

Consultant answered 19/3, 2010 at 11:35 Comment(1)
I just listed TcxSplitter as an example that I had to hand. It most commonly happens with TForm.Sloven
A
0

I encounter a lot of noise from random (dis)appearances of these:

ExplicitLeft = 0
ExplicitTop = 0
ExplicitWidth = 0
ExplicitHeight = 0

So I wrote a tool that removes only these (all 4 exist and are 0) from DFM files:

https://github.com/gonutz/dfm_clear_explicit_zeros

Aerobe answered 12/11, 2021 at 9:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.