Jump to content
dummzeuch

remove ExplicitXxxx properties

Recommended Posts

Does anybody know how to prevent the ExplicitTop/Left/Width/Height properties from being written to the DFM file? I never saw any use for them and always installed Andreas Hausladen's DDevExtensions which allows to remove them. But since Andy apparently doesn't have access to the latest Delphi version there is no DDevExtensions  (and also no IDE Fix Pack) for Delphi 10.4(.1) and I would like to add that functionality to GExperts. I tried, but so far failed. Any hints?

Edited by dummzeuch
  • Like 1

Share this post


Link to post

Delphi IDE uses System.Classes.TStream.WriteDescendentRes to serialize the form/components properties. Property that belongs to the class is handled by System.Classes.TWriter.WriteProperty. However internal property such ExplicitXxx is handled by System.Classes.TWriter.DefineProperty. 

// TPersistent.DefineProperties defines Explicit properties. and TWriter.DefineProperty encode them.
procedure TControl.DefineProperties(Filer: TFiler);
begin
  ...
  Filer.DefineProperty('IsControl', ReadIsControl, WriteIsControl, DoWriteIsControl);
  Filer.DefineProperty('ExplicitLeft', ReadExplicitLeft, WriteExplicitLeft, not (csReading in ComponentState) and DoWriteExplicit(edLeft));
  Filer.DefineProperty('ExplicitTop', ReadExplicitTop, WriteExplicitTop, not (csReading in ComponentState) and DoWriteExplicit(edTop));
  Filer.DefineProperty('ExplicitWidth', ReadExplicitWidth, WriteExplicitWidth, not (csReading in ComponentState) and DoWriteExplicit(edWidth));
  Filer.DefineProperty('ExplicitHeight', ReadExplicitHeight, WriteExplicitHeight, not (csReading in ComponentState) and DoWriteExplicit(edHeight));
end;

In a nutshell, hooking TWriter.DefineProperty will get you off EplicitXxx:

procedure InterceptDefineProperty(Obj: TWriter; const Name: string; ReadData: TReaderProc; WriteData: TWriterProc; HasData: Boolean);
begin
  // do nothing !!! or write a filter to allow certain ExplicitXxx.
end;

// install the hook :
DefinePropertyPtr := GetProcAddress(GetModuleHandle('rtl260.bpl'), '@System@Classes@TWriter@DefineProperty$qqrx20System@UnicodeStringynpqqrp22System@Classes@TReader$vynpqqrp22System@Classes@TWriter$vo');
@TrampolineDefineProperty := InterceptCreate(DefinePropertyPtr, @InterceptDefineProperty);

 

  • Like 2
  • Thanks 2

Share this post


Link to post
1 hour ago, David Schwartz said:

What are they used for? I could never tell why they even started showing up.

In theory they are used to preserve the original size and position of controls when they are set to alClient, alTop etc. so when they are set back so alNone at a later time, they automatically revert to their original size and position.

 

Personally I never found that useful and since these values tend to change very often (no idea why, they shouldn't) they pollute the DFM diffs and history.

  • Like 1
  • Thanks 1

Share this post


Link to post

I've never figured out why they change so often either. And with or without them, in the rare cases where I select None for an alignment, it usually just leave the object in the same place and dimensions. I don't care if it reverts back to something else or not.

Share this post


Link to post

I apparently saw some expert allowing to exclude some properties from saved DFM... maybe CnPack? I haven't tried too much experts so if not GExperts then it should be CnPack

Share this post


Link to post

@dummzeuch, With TortoiseSVN you could implement a local pre-commit hook that removes the Explicit properties from all or just the modified .dfm files. We do this to normalize .dproj files before commit.

  • Like 1

Share this post


Link to post
On 9/5/2020 at 11:46 PM, Mahdi Safsafi said:

 


procedure InterceptDefineProperty(Obj: TWriter; const Name: string; ReadData: TReaderProc; WriteData: TWriterProc; HasData: Boolean);
begin
  // do nothing !!! or write a filter to allow certain ExplicitXxx.
end;

// install the hook :
DefinePropertyPtr := GetProcAddress(GetModuleHandle('rtl260.bpl'), '@System@Classes@TWriter@DefineProperty$qqrx20System@UnicodeStringynpqqrp22System@Classes@TReader$vynpqqrp22System@Classes@TWriter$vo');
@TrampolineDefineProperty := InterceptCreate(DefinePropertyPtr, @InterceptDefineProperty);

Thanks, that really helped me much developing an own plugin (using rtl270.bpl for D10.4.1)

 

Edited by DaSteMpO

Share this post


Link to post

I freaking loathe those explicit... props.  Whoever introduced them should have had all their key caps removed.

  • Haha 1

Share this post


Link to post
46 minutes ago, Lars Fosdal said:

I freaking loathe those explicit... props.  Whoever introduced them should have had all their key caps removed.

Not a fan of them, either, but I recognize the reasons they were added. There were also some attempts long ago to implement form scaling, for which the explicits would be helpful. Or would, if such scaling were practical. But it's not (see rounding errors) since we would need all visuals dimensioned in floating point to make that work.

Share this post


Link to post

I know I am late to the party, but you might try the attached package for Delphi 10.4.1.

It uses the hooking code from Andreas Hausladen's VclFixPack v1.4 to patch the TControl.DefineProperties method to a modified code, which does not write those Explicit* properties to the DFM file.

Unpack the zip archive, open DControlsFix.dpk in Delphi 10.4.1, compile & install. There is nothing to customize. If this package is installed, the patch is active. If you like to get the default behaviour back, just uninstall the package.

Use at your own risk 😉

 

DControlsFix.zip

  • Like 2
  • Thanks 7

Share this post


Link to post
On 9/5/2020 at 1:19 PM, dummzeuch said:

Does anybody know how to prevent the ExplicitTop/Left/Width/Height properties from being written to the DFM file? I never saw any use for them and always installed Andreas Hausladen's DDevExtensions which allows to remove them. But since Andy apparently doesn't have access to the latest Delphi version there is no DDevExtensions  (and also no IDE Fix Pack) for Delphi 10.4(.1) and I would like to add that functionality to GExperts. I tried, but so far failed. Any hints?

Did you succeed in integrating it into GExperts?

Share this post


Link to post
7 hours ago, DaSteMpO said:

Did you succeed in integrating it into GExperts?

No, didn't try yet. And with @Achim Kalwa's plugin, available (which I haven't tried yet either), I'm not sure I'll bother.

Share this post


Link to post
50 minutes ago, dummzeuch said:

No, didn't try yet. And with @Achim Kalwa's plugin, available (which I haven't tried yet either), I'm not sure I'll bother.

We're not all on 10.4.1.....

Share this post


Link to post

In fact first attempt was to integrate this little patch into GExperts. There is already GX_VCLFixPack.pas, which is a slightly modified version of Andreas' VclFixPack.pas. It is currently not in use (disabled by $IFDEF) and needs some cleanup, e.g. remove unused and old Win95 code 🙂. But for a "complete" GX Expert it would be neccessary to have at least an on/off configuration switch in the IDE settings section; but I did not dig deep enough to implement such a thing. And some kind of documentation would be helpful, too.

Maybe I'll find some spare time at the weekend for creating a patch to GExperts.

 

  • Thanks 1

Share this post


Link to post
On 9/28/2020 at 7:11 PM, Achim Kalwa said:

I know I am late to the party, but you might try the attached package for Delphi 10.4.1.

It uses the hooking code from Andreas Hausladen's VclFixPack v1.4 to patch the TControl.DefineProperties method to a modified code, which does not write those Explicit* properties to the DFM file.

Unpack the zip archive, open DControlsFix.dpk in Delphi 10.4.1, compile & install. There is nothing to customize. If this package is installed, the patch is active. If you like to get the default behaviour back, just uninstall the package.

Use at your own risk 😉

 

DControlsFix.zip

Works!

 

Thnaks,.

Share this post


Link to post
On 10/1/2020 at 10:45 PM, Achim Kalwa said:

Maybe I'll find some spare time at the weekend for creating a patch to GExperts.

I just converted your code into an expert in revision #3418

  • Like 3

Share this post


Link to post

Hi Guys,

I am late to the party here..

Can someone explain what the issue/problem is?

How would it manifest itself to me?

Why is it good to remove it?  i.e. what benefit does it give me?

 

Regards & TIA,

Ian

Share this post


Link to post
19 hours ago, Ian Branch said:

Can someone explain what the issue/problem is?

How would it manifest itself to me?

Why is it good to remove it?  i.e. what benefit does it give me?

... and other older posts in this topic.

Edited by dummzeuch

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×