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:
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.
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:
- Run the application
- Click on the Get Values button
- Values from Figure 1 are displayed in the Memo control
- Click on the Align Client button
- Click on the Get Values button again and Figure 2 displays the added Memo control contents
- Click on the Align None button
- 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.
|
|