Recent

Author Topic: activex.pp definition problem  (Read 1808 times)

440bx

  • Hero Member
  • *****
  • Posts: 6063
activex.pp definition problem
« on: July 07, 2025, 11:30:43 pm »
Hello,

In activex.pp there are a large number of GUID definitions that are supposed to be constant but, they are not.

for instance, it is possible to do this:
Code: Pascal  [Select][+][-]
  1.   GUID_NULL.D1            := 1;
  2.   IID_IEnumConnections.D1 := 1;
  3.  
Known GUIDs should not be changeable.
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 18728
  • To Europe: simply sell USA bonds: dollar collapses
Re: activex.pp definition problem
« Reply #1 on: July 08, 2025, 06:54:30 am »
Also the case in C++ btw... not a Pascal issue.
I guess you can declare these GUIDS as typed const, but in {$J-} state which makes them immutable.
I thought you knew that:
Code: Pascal  [Select][+][-]
  1. {$push}{$J-}
  2. const
  3.   myguid:TGUid = '{77DE903C-1453-4622-93A0-1C46B74627B9}';
  4. {$pop}
  5. begin
  6.   myguid.d1 := 5;  // Error: Can't assign values to const variable.
  7. end.
It should be fine to compile the whole interface section of the activex unit in forced {$J-} state.
(If that is not already the case)
The guid ends up in .rodata and so is immutable:
Code: ASM  [Select][+][-]
  1. .section .rodata.n_TC_$P$PROGRAM_$$_MYGUID,"aw"
  2.         .balign 4
  3. .globl  TC_$P$PROGRAM_$$_MYGUID
  4. TC_$P$PROGRAM_$$_MYGUID:
  5.         .long   2011074620
  6.         .short  5203,17954
  7.         .byte   147,160,28,70,183,70,39,185  # same guid, but in decimal.
  8. # End asmlist al_rotypedconsts
Maybe @Marcov can check if this is the case and otherwise protect the interface section with {$J-} ?
This should not otherwise affect the code. Must be done with {$push}/{$pop}, though.
« Last Edit: July 08, 2025, 07:34:53 am by Thaddy »
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

440bx

  • Hero Member
  • *****
  • Posts: 6063
Re: activex.pp definition problem
« Reply #2 on: July 08, 2025, 07:54:33 am »
I thought you knew that:
You actually thought ?... I hope you didn't experience too much pain.
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 18728
  • To Europe: simply sell USA bonds: dollar collapses
Re: activex.pp definition problem
« Reply #3 on: July 08, 2025, 08:04:36 am »
Nah... :D Hope its solves the problem, though.

I did:
- around line 101 {$PUSH}{$WRITEABLECONST OFF} // start of GUID consts
- around line 189 {$POP} // end of GUID consts, alternatively around line 4954 for the pop. Just above implementation.
That seems enough. Not really good with patching with GIT yet.
push/pop is necessary to avoid settings spill. 101/189 seems the most "correct": least code affected.

I will leave that up to Marcov.
Just in case:
Code: Pascal  [Select][+][-]
  1. packages/winunits-base/src/activex.pp | 4 ++--
  2.  1 file changed, 2 insertions(+), 2 deletions(-)
  3.  
  4. diff --git a/packages/winunits-base/src/activex.pp b/packages/winunits-base/src/activex.pp
  5. index 56dec102fe..2420a7e5bc 100644
  6. --- a/packages/winunits-base/src/activex.pp
  7. +++ b/packages/winunits-base/src/activex.pp
  8. @@ -98,7 +98,7 @@
  9.     TOleColor           = OLE_COLOR;
  10.     POleColor           = LPOle_Color;
  11.     HHandle             = UINT_PTR;
  12. -
  13. +{$PUSH}{$WRITABLECONST OFF}
  14.  CONST
  15.     GUID_NULL  : TGUID =  '{00000000-0000-0000-0000-000000000000}';
  16.     IID_IPrint : TGUID = '{B722BCC9-4E68-101B-A2BC-00AA00404770}';
  17. @@ -186,7 +186,7 @@
  18.     IID_IOleCache2 : TGUID = '{00000128-0000-0000-C000-000000000046}';
  19.     IID_IOleCacheControl : TGUID = '{00000129-0000-0000-C000-000000000046}';
  20.     IID_IOleItemContainer : TGUID = '{0000011C-0000-0000-C000-000000000046}';
  21. -
  22. +{$POP}
  23.  
  24.       // bit flags for IExternalConnection
  25.  CONST
  26.  
Should be close to a correct patch. (against trunk from today 10:00)
« Last Edit: July 08, 2025, 10:31:44 am by Thaddy »
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

nanobit

  • Full Member
  • ***
  • Posts: 183
Re: activex.pp definition problem
« Reply #4 on: July 09, 2025, 07:19:01 pm »
Unfortunately {$J+} is default in FPC,
whereas Delphi has the preferable default {$J-} since Delphi 6.

Thaddy

  • Hero Member
  • *****
  • Posts: 18728
  • To Europe: simply sell USA bonds: dollar collapses
Re: activex.pp definition problem
« Reply #5 on: July 09, 2025, 09:05:14 pm »
See the bug report..... <sigh> And your statement about Delphi is not true D7 behaves the same, D12.1 behaves the same.
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

nanobit

  • Full Member
  • ***
  • Posts: 183
Re: activex.pp definition problem
« Reply #6 on: July 09, 2025, 09:37:10 pm »
Excerpt from Delphi 6 Developer’s Guide (Steve Teixeira):

Quote
Migrating from Delphi 5: Although compatibility between Delphi 5 and 6 is quite good, there are a few minor issues you should be aware of as you make the move.
Writable Typed Constants
The default state of the $J compiler switch (also known as $WRITEABLECONST) is now OFF,
where it was ON in previous versions. This means that attempts to assign to typed constants will raise a compiler error unless you explicitly enable this behavior using $J+.

gues1

  • Guest
Re: activex.pp definition problem
« Reply #7 on: July 09, 2025, 10:27:36 pm »
In "Delphi 7 Object Pascal Language Guide" at page 5-43:

Quote
In the default {$J-} compiler state, typed constants can not have new values assigned
to them; they are, in effect, read-only variables.

Thaddy

  • Hero Member
  • *****
  • Posts: 18728
  • To Europe: simply sell USA bonds: dollar collapses
Re: activex.pp definition problem
« Reply #8 on: July 10, 2025, 01:03:29 pm »
Yes. Hence my patch.
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

 

TinyPortal © 2005-2018