Tuesday, February 28, 2006

D2006: What on earth are these Explicit* properties in my DFM

If you need to make sure your application can still be compiled in previous Delphi versions you need to watch out for some new properties that are added by Delphi 2006 to your DFM. These new properties are for all TControl descendants and are called ExplicitTop, ExplicitLeft, ExplicitHeight and ExplicitWidth. These are not actually published properties; you won’t find them in the object inspector.

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.

You can download the example here to play along at home if you like (executable included):
http://www.jed-software.com/files/ExplicitProps.zip

This example takes a TPanel and changes its align property value from

alNone -> alClient -> alNone

Example Usage:
  1. Run the application
  2. Click on the Get Values button
  3. Values from Figure 1 are displayed in the Memo control
  4. Click on the Align Client button
  5. Click on the Get Values button again and Figure 2 displays the added Memo control contents
  6. Click on the Align None button
  7. Click on the Get Values button a final time and the Memo control should have the same values added to it that were added in Step 3.



So what has changed?
In previous Delphi versions if the align property was changed to alClient and then back to alNone, the control would stay as if it was aligned client still. These new properties mean that the original bounds is restored when this occurs. As noted with the example.

When the panel was aligned client it up the left over client area of the form; as expected. When clicking on the Align None button the panel was restored back to its size prior to setting Align to alClient.

If you want to know the specific conditions for having these properties written to the DFM check out the DoWriteExplicit function in the DefineProperties method for TControl.





Figure 1



Align is alNone

ExplicitTop: 40

ExplicitLeft: 256

ExplicitHeight: 185

ExplicitWidth: 329

Top: 40

Left: 256

Height: 185

Width: 329

----------------------






Figure 2



Align is alClient

ExplicitTop: 40

ExplicitLeft: 256

ExplicitHeight: 185

ExplicitWidth: 329

Top: 0

Left: 193

Height: 456

Width: 450

----------------------






8 Comments:

Anonymous Anonymous said...

Jeremy, I notice that you haven't benn getting many comments on your recent posts. I can see them from IE 6, but not from my RSS reader.

Check the RSS feed validation:
http://www.feedvalidator.org/check?url=http://www.2rss.com/atom2rss.php?atom=http%3A//jedqc.blogspot.com/atom.xml

HTH.

7:27 AM  
Blogger JED said...

Thanks Brad.

Not sure why that has just started happening. Might be a bad post in there.

You could just subscribe to the atom feed which is what I use in RSSBandit and it works fine. I have also added a feed at FeedBurner that works. This is the URL:

http://feeds.feedburner.com/JedSoftware

thanks again

8:50 AM  
Blogger Charlie said...

Id completely forgotten about your blog.. I was reminded as Ive started one here.. http://virtualise.blogspot.com! for all my IT based ramblings.. currently Im rambling about VMware.. until I get more of my delphi course completed.

9:12 AM  
Anonymous Anonymous said...

Hi Jeremy,

(no, I haven't forgotten your blog!)
It is not clear from your article what can be done to prevent the Explicit* properties from getting written to the form file!
I do want to share some forms between D6/D2006 if at all possible.

BTW this Explicit* thing sounds like a solution looking for its problem. I haven't seen the QC feature request for this. I almost always set the Align/Anchor properties at design time and don't care if Delphi forgets what the original coordinates were.

Hmmm.

Kris

9:34 PM  
Anonymous Anonymous said...

Vote at http://qc.borland.com/wc/qcmain.aspx?d=22615 to have this "feature" removed (or at least let these properties not be stored). This is really not worth breaking compatibility with previous Delphi versions.

4:30 PM  
Anonymous Anonymous said...

What's the big deal?
All Delphi versions add new properties to DFM files.
It';s called progress.

4:36 AM  
Blogger JED said...

Hi Chris,

I guess you were responding to the comment by Avatar Zondertau.

It can be annoying when you have to support different IDE versions with your projects. As you say it is the price of progress and while frustrating it doesn't bother me that much.

9:08 AM  
Blogger Warren said...

The JEDI JCL/JVCL project folks have a little utility called the "DFM Cleaner" that you can use to strip out this stuff automagically. I have a batch file I double click on before opening a project in delphi 7. It removes these properties, saving me a lot of headaches keeping a project that will build in D7 and D2007.

Warren

1:22 AM  

Post a Comment

<< Home