Recent

Author Topic: [SOLVED] Cleanup of duplicate declarations of constants  (Read 2816 times)

lagprogramming

  • Sr. Member
  • ****
  • Posts: 407
[SOLVED] Cleanup of duplicate declarations of constants
« on: July 09, 2023, 04:30:07 pm »
Both lcl/interfaces/win32/win32extra.pas and lcl/interfaces/customdrawn/customdrawn_winextra.pas files contain the following lines:
Code: Pascal  [Select][+][-]
  1. { Win32 API constants not included in windows.pp }
  2. const
  3.   // Layout orientation
  4.   LAYOUT_RTL                        = $00000001; // Right to left
  5.   LAYOUT_BTT                        = $00000002; // Bottom to top
  6.   LAYOUT_VBH                        = $00000004; // Vertical before horizontal
  7.   LAYOUT_ORIENTATIONMASK            = (LAYOUT_RTL or LAYOUT_BTT or LAYOUT_VBH);
  8.   LAYOUT_BITMAPORIENTATIONPRESERVED = $00000008;
  9.   // not defined in fpc 2.4.3
  10.   GCLP_HBRBACKGROUND                = -10;

The above constants have been included in FPC's rtl through the following commits:
Oct 17, 2010 Commit 8304d2c1: * adds gwlp and gclp constants, mantis 17656 and 17655
https://gitlab.com/freepascal.org/fpc/source/-/commit/8304d2c1c5240cd8292b87ca2835bfb3f988d1fe
Jul 06, 2013 Commit 609f6255: * added layout constants.
https://gitlab.com/freepascal.org/fpc/source/-/commit/609f6255d4d371c993d8e231efc83ee97523d9bd

This means that the constants declarations in the LCL have become obsolete 10 years ago. The ones in FPC's rtl should be enough.
The following patch removes the declarations from the LCL.
Code: Pascal  [Select][+][-]
  1. diff --git a/lcl/interfaces/customdrawn/customdrawn_winextra.pas b/lcl/interfaces/customdrawn/customdrawn_winextra.pas
  2. index 1d7a36da24..d155284efe 100644
  3. --- a/lcl/interfaces/customdrawn/customdrawn_winextra.pas
  4. +++ b/lcl/interfaces/customdrawn/customdrawn_winextra.pas
  5. @@ -43,17 +43,6 @@ type
  6.      DisabledWindows: TList;
  7.    end;
  8.  
  9. -{ Win32 API constants not included in windows.pp }
  10. -const
  11. -  // Layout orientation
  12. -  LAYOUT_RTL                        = $00000001; // Right to left
  13. -  LAYOUT_BTT                        = $00000002; // Bottom to top
  14. -  LAYOUT_VBH                        = $00000004; // Vertical before horizontal
  15. -  LAYOUT_ORIENTATIONMASK            = (LAYOUT_RTL or LAYOUT_BTT or LAYOUT_VBH);
  16. -  LAYOUT_BITMAPORIENTATIONPRESERVED = $00000008;
  17. -  // not defined in fpc 2.4.3
  18. -  GCLP_HBRBACKGROUND                = -10;
  19. -
  20.  type
  21.    tagMENUBARINFO = record
  22.      cbSize: DWORD;
  23. diff --git a/lcl/interfaces/win32/win32extra.pas b/lcl/interfaces/win32/win32extra.pas
  24. index 5997d81fe4..9d7bdc7787 100644
  25. --- a/lcl/interfaces/win32/win32extra.pas
  26. +++ b/lcl/interfaces/win32/win32extra.pas
  27. @@ -28,17 +28,6 @@ interface
  28.  uses
  29.    Classes, LCLType, Windows, GraphType, SysUtils, ActiveX, ShlObj;
  30.  
  31. -{ Win32 API constants not included in windows.pp }
  32. -const
  33. -  // Layout orientation
  34. -  LAYOUT_RTL                        = $00000001; // Right to left
  35. -  LAYOUT_BTT                        = $00000002; // Bottom to top
  36. -  LAYOUT_VBH                        = $00000004; // Vertical before horizontal
  37. -  LAYOUT_ORIENTATIONMASK            = (LAYOUT_RTL or LAYOUT_BTT or LAYOUT_VBH);
  38. -  LAYOUT_BITMAPORIENTATIONPRESERVED = $00000008;
  39. -  // not defined in fpc 2.4.3
  40. -  GCLP_HBRBACKGROUND                = -10;
  41. -
  42.  type
  43.    tagMENUBARINFO = record
  44.      cbSize: DWORD;
  45.  
« Last Edit: August 20, 2023, 10:28:09 am by lagprogramming »

dsiders

  • Hero Member
  • *****
  • Posts: 1282
Re: Cleanup of duplicate declarations of constants
« Reply #1 on: July 09, 2023, 05:41:57 pm »
Both lcl/interfaces/win32/win32extra.pas and lcl/interfaces/customdrawn/customdrawn_winextra.pas files contain the following lines:
Code: Pascal  [Select][+][-]
  1. { Win32 API constants not included in windows.pp }
  2. const
  3.   // Layout orientation
  4.   LAYOUT_RTL                        = $00000001; // Right to left
  5.   LAYOUT_BTT                        = $00000002; // Bottom to top
  6.   LAYOUT_VBH                        = $00000004; // Vertical before horizontal
  7.   LAYOUT_ORIENTATIONMASK            = (LAYOUT_RTL or LAYOUT_BTT or LAYOUT_VBH);
  8.   LAYOUT_BITMAPORIENTATIONPRESERVED = $00000008;
  9.   // not defined in fpc 2.4.3
  10.   GCLP_HBRBACKGROUND                = -10;

The above constants have been included in FPC's rtl through the following commits:
Oct 17, 2010 Commit 8304d2c1: * adds gwlp and gclp constants, mantis 17656 and 17655
https://gitlab.com/freepascal.org/fpc/source/-/commit/8304d2c1c5240cd8292b87ca2835bfb3f988d1fe
Jul 06, 2013 Commit 609f6255: * added layout constants.
https://gitlab.com/freepascal.org/fpc/source/-/commit/609f6255d4d371c993d8e231efc83ee97523d9bd

This means that the constants declarations in the LCL have become obsolete 10 years ago. The ones in FPC's rtl should be enough.
The following patch removes the declarations from the LCL.
Code: Pascal  [Select][+][-]
  1. diff --git a/lcl/interfaces/customdrawn/customdrawn_winextra.pas b/lcl/interfaces/customdrawn/customdrawn_winextra.pas
  2. index 1d7a36da24..d155284efe 100644
  3. --- a/lcl/interfaces/customdrawn/customdrawn_winextra.pas
  4. +++ b/lcl/interfaces/customdrawn/customdrawn_winextra.pas
  5. @@ -43,17 +43,6 @@ type
  6.      DisabledWindows: TList;
  7.    end;
  8.  
  9. -{ Win32 API constants not included in windows.pp }
  10. -const
  11. -  // Layout orientation
  12. -  LAYOUT_RTL                        = $00000001; // Right to left
  13. -  LAYOUT_BTT                        = $00000002; // Bottom to top
  14. -  LAYOUT_VBH                        = $00000004; // Vertical before horizontal
  15. -  LAYOUT_ORIENTATIONMASK            = (LAYOUT_RTL or LAYOUT_BTT or LAYOUT_VBH);
  16. -  LAYOUT_BITMAPORIENTATIONPRESERVED = $00000008;
  17. -  // not defined in fpc 2.4.3
  18. -  GCLP_HBRBACKGROUND                = -10;
  19. -
  20.  type
  21.    tagMENUBARINFO = record
  22.      cbSize: DWORD;
  23. diff --git a/lcl/interfaces/win32/win32extra.pas b/lcl/interfaces/win32/win32extra.pas
  24. index 5997d81fe4..9d7bdc7787 100644
  25. --- a/lcl/interfaces/win32/win32extra.pas
  26. +++ b/lcl/interfaces/win32/win32extra.pas
  27. @@ -28,17 +28,6 @@ interface
  28.  uses
  29.    Classes, LCLType, Windows, GraphType, SysUtils, ActiveX, ShlObj;
  30.  
  31. -{ Win32 API constants not included in windows.pp }
  32. -const
  33. -  // Layout orientation
  34. -  LAYOUT_RTL                        = $00000001; // Right to left
  35. -  LAYOUT_BTT                        = $00000002; // Bottom to top
  36. -  LAYOUT_VBH                        = $00000004; // Vertical before horizontal
  37. -  LAYOUT_ORIENTATIONMASK            = (LAYOUT_RTL or LAYOUT_BTT or LAYOUT_VBH);
  38. -  LAYOUT_BITMAPORIENTATIONPRESERVED = $00000008;
  39. -  // not defined in fpc 2.4.3
  40. -  GCLP_HBRBACKGROUND                = -10;
  41. -
  42.  type
  43.    tagMENUBARINFO = record
  44.      cbSize: DWORD;
  45.  

You can't just remove them from LCL. The symbols in LCL need to be deprecated so the community has an opportunity to fix their code before it blows up. It doesn't matter how long ago they were introduced in RTL.

This also does not address the scores of units in LCL that need to add wintypes to the uses clause and test whether win32extra is still needed.

Preview the next Lazarus documentation release at: https://dsiders.gitlab.io/lazdocsnext

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11944
  • FPC developer.
Re: Cleanup of duplicate declarations of constants
« Reply #2 on: July 09, 2023, 11:10:42 pm »
You can't just remove them from LCL. The symbols in LCL need to be deprecated so the community has an opportunity to fix their code before it blows up. It doesn't matter how long ago they were introduced in RTL.

They have had 10 years, and haven't noticed there were two sets (that might switch on the USES clause order).

In cases of low chances on trouble like this, I think this can be accelerated.

The next major version of FPC will probably make even more obsolete, since then the moving of constants and other stuff to uitypes

Quote
This also does not address the scores of units in LCL that need to add wintypes to the uses clause and test whether win32extra is still needed.

"Wintypes"?  Afaik we never supported that. Or do you uitypes?

uitypes and other units from the same Delphi generation(s) are still being expanded, so probably wait till the next major FPC version (or the first point release after that) to do a big clean.

dsiders

  • Hero Member
  • *****
  • Posts: 1282
Re: Cleanup of duplicate declarations of constants
« Reply #3 on: July 10, 2023, 02:11:41 am »
You can't just remove them from LCL. The symbols in LCL need to be deprecated so the community has an opportunity to fix their code before it blows up. It doesn't matter how long ago they were introduced in RTL.

They have had 10 years, and haven't noticed there were two sets (that might switch on the USES clause order).

In cases of low chances on trouble like this, I think this can be accelerated.

The next major version of FPC will probably make even more obsolete, since then the moving of constants and other stuff to uitypes

Quote
This also does not address the scores of units in LCL that need to add wintypes to the uses clause and test whether win32extra is still needed.

"Wintypes"?  Afaik we never supported that. Or do you uitypes?

uitypes and other units from the same Delphi generation(s) are still being expanded, so probably wait till the next major FPC version (or the first point release after that) to do a big clean.

Okay, wintypes was wrong.

Doesn't change the fact that the symbols need to be deprecated in LCL before they are summarily yanked. In reality, the constants lag is on about should have been deprecated 10 years ago. But they were not.

system.uitypes is another matter. LCL code has already deprecated those. Maybe someday, where there's a  dotted namespace unit in docs, they can actually be removed.
Preview the next Lazarus documentation release at: https://dsiders.gitlab.io/lazdocsnext

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11944
  • FPC developer.
Re: Cleanup of duplicate declarations of constants
« Reply #4 on: July 10, 2023, 10:22:30 am »
This is a undocumented patch/hack unit for the lcl win32 interface writers benefit. Not end-user functionality(*). IMHO it is a bit over the top to insist on full cycle deprecation cycles just for the case somebody writes "win32extra.identifier" on a constant that is now in unit Windows in Delphi and Lazarus. (maybe even flag the whole unit as experimental or so that end users get a warning when they use it?)

But if you insist I'll do it anyway, and compare all constants to trunk.

The system.uitypes transition will be more profound, but it will also be a bigger relief when we are through that transition. The big advantages are however in FPC and other non LCL graphics and UI, where fcl-image now for the first time can use useful types like "TColor", for Lazarus it mostly is only pain.

(*) and keep in mind that win32/64 users usually use latest and greatest release, while on Linux versions lag due to package systems for LTE releases not movign on
« Last Edit: July 10, 2023, 10:25:07 am by marcov »

dsiders

  • Hero Member
  • *****
  • Posts: 1282
Re: Cleanup of duplicate declarations of constants
« Reply #5 on: July 10, 2023, 03:17:14 pm »
This is a undocumented patch/hack unit for the lcl win32 interface writers benefit. Not end-user functionality(*). IMHO it is a bit over the top to insist on full cycle deprecation cycles just for the case somebody writes "win32extra.identifier" on a constant that is now in unit Windows in Delphi and Lazarus. (maybe even flag the whole unit as experimental or so that end users get a warning when they use it?)

But if you insist I'll do it anyway, and compare all constants to trunk.

I'm not insisting that you do anything. I'm hoping that whoever picks up this code, and lobs it over another wall, decides to do the right thing and deprecates the symbols instead of deleting them.

The system.uitypes transition will be more profound, but it will also be a bigger relief when we are through that transition. The big advantages are however in FPC and other non LCL graphics and UI, where fcl-image now for the first time can use useful types like "TColor", for Lazarus it mostly is only pain.

(*) and keep in mind that win32/64 users usually use latest and greatest release, while on Linux versions lag due to package systems for LTE releases not movign on

I'd be happy with having system.uitypes in rtl.chm. The code is in place, but the docs aren't.
Preview the next Lazarus documentation release at: https://dsiders.gitlab.io/lazdocsnext

lagprogramming

  • Sr. Member
  • ****
  • Posts: 407
Re: Cleanup of duplicate declarations of constants
« Reply #6 on: July 11, 2023, 09:55:52 am »
Searching the lazarus directory for the mentioned constants shows that only LAYOUT_RTL is actively used, and it's used in just 2 files with a total of 3 occurrences:
lazarus/lcl/interfaces/win32/win32callback.inc
win32callback.inc (534,39) SetLayout(CurDoubleBuffer.DC, LAYOUT_RTL);
lazarus/lcl/interfaces/win32/win32wsmenus.pp
win32wsmenus.pp (814,21) SetLayout(AHDC, LAYOUT_RTL);
win32wsmenus.pp (883,25) SetLayout(AHDC, LAYOUT_RTL);
None of the other constants is actively used in the Lazarus sources.

lcl/interfaces/win32/win32extra.pas already has the windows unit in uses, which means it will use the constants from FPC's rtl.
lazarus/lcl/interfaces/win32/win32callback.inc is included in win32int.pp, which has the windows unit in uses. This means that it will use the constants from FPC's rtl.
lcl/interfaces/win32/win32wsmenus.pp already has the windows unit in uses, which means it will use the constants from FPC's rtl.
So I don't see a problem in applying the patch to the development Lazarus sources. I don't use Windows, but I had no problems in building Windows executables from Linux using Lazarus source files without those constants.

 

TinyPortal © 2005-2018