Jump to content

ERROR - Can not redeclare a constant.


Recommended Posts

In my project is included 

_RegFunc.au3

And its dependecies (requested BEFORE compilation success):

AutoItConstants.au3
ColorConstants.au3
Constants.au3
DirConstants.au3
FileConstants.au3
MsgBoxConstants.au3
ProcessConstants.au3
StringConstants.au3
TrayConstants.au3


All the code is:

 

#include <_RegFunc.au3>

Local $REGISTRYKEY1 = "HKEY_CURRENT_USER\Software\MyKey"
Local $PORTABLEKEY1 = "Backup\MyKey.reg"

_RegMoveKey($REGISTRYKEY1, $REGISTRYKEY1 & "-Backup")
_RegCopyKey($PORTABLEKEY1, $REGISTRYKEY1)

 

The compilation goes well, in both case, with code above and with explicit Call command (see yesterday's code).
At running the executable return this error:


Line 519 (File "Path\...\Registry.exe"):
Error can not redeclare a constant.

 

Don't run. What's the reason?

The explanation (in _RegFunc.au3) say:

; #FUNCTION# ====================================================================================================
; Name...........:  _RegMoveKey
; Description....:  Move a registry key, including all subkeys and values
; Syntax.........:  _RegMoveKey($s_key, $d_key)
; Parameters.....:  $s_key  - Source key
;                   $d_key  - Destination key
;
; Return values..:  Success - 1
;                   Failure - 0 and sets @error
;                           |-1 - Source and destination keys are the same
;                           | 1 - Source does not exist
;                           | 2 - Failed to write destination key (@extended contains _RegWrite error code)
;                           | 3 - Failed to read one or more values from source key or subkey(s)
;                           | 4 - Failed to delete source key (@extended contains _RegDelete error code)
; Author.........:  Erik Pilsits
; Modified.......:
; Remarks........:
; Related........:
; Link...........:
; Example........:
; ===============================================================================================================
Func _RegMoveKey($s_key, $d_key)
    Local $ret = _RegCopyKey($s_key, $d_key, True)
    Return SetError(@error, @extended, $ret)
EndFunc   ;==>_RegMoveKey




; #FUNCTION# ====================================================================================================
; Name...........:  _RegCopyKey
; Description....:  Recursively copy a registry key, including all subkeys and values
; Syntax.........:  _RegCopyKey($s_key, $d_key)
; Parameters.....:  $s_key  - Source key
;                   $d_key  - Destination key
;                   $delete - [Internal]
;
; Return values..:  Success - 1
;                   Failure - 0 and sets @error
;                           |-1 - Source and destination keys are the same
;                           | 1 - Source does not exist
;                           | 2 - Failed to write destination key (@extended contains _RegWrite error code)
;                           | 3 - Failed to read one or more values from source key or subkey(s)
; Author.........:  Erik Pilsits
; Modified.......:
; Remarks........:
; Related........:
; Link...........:
; Example........:
; ===============================================================================================================
Func _RegCopyKey($s_key, $d_key, $delete = False)
    If $s_key = $d_key Then Return SetError(-1, 0, 0) ; destination is the same as source
    If Not _RegKeyExists($s_key) Then Return SetError(1, 0, 0)
    _RegWrite($d_key) ; write destination key in case source key empty
    If @error Then Return SetError(2, @error, 0)
    ; value loop
    Local $i = 0, $val, $data, $err = 0
    While 1
        $val = _RegEnumValue($s_key, $i)
        If @error Then ExitLoop ; no more values
        _RegCopyValue($s_key, $val, $d_key)
        If @error Then
            $err = 3
            ContinueLoop ; some error reading value, skip it
        EndIf
        $i += 1
    WEnd
    ; key loop
    Local $key
    $i = 0
    While 1
        $key = _RegEnumKey($s_key, $i)
        If @error Then ExitLoop ; no more keys
        _RegCopyKey($s_key & "\" & $key, $d_key & "\" & $key) ; recurse
        If @error = 3 Then $err = 3 ; test for errors reading subkey values
        $i += 1
    WEnd
    If $err Then Return SetError($err, 0, 0) ; error(s) reading value(s) or subkey value(s)
    ; move key
    If $delete Then
        ; delete source key only if copy was entirely successful
        _RegDelete($s_key)
        If @error Then Return SetError(4, @error, 0) ; error deleting source key
    EndIf
    Return SetError(0, 0, 1)
EndFunc   ;==>_RegCopyKey

I have tryed also a minimal code:

#include <_RegFunc.au3>

_RegMoveKey("HKEY_CURRENT_USER\Software\MyKey", "HKEY_CURRENT_USER\Software\MyKey2")

 

The result is the same.

 

All the code (except _RegFunc.au3) is downloaded from GitHub with accurate copy/paste (direct download create unwanted characters in the code).
All the files are checked one by one to verify the correct copy.

 

Jos, I wish this way of messaging is right for you! :)

Link to comment
Share on other sites

  • Developers

Open _Regfunc.au3 and simple do a run. (preferably after you have installed the Full version of SciTE4Autoit3 as that runs au3check for you. I believe I told you this before...right?).
You will see you get the error right away with any extra code and it will tell you that Line 20 has the error which is because included file "AutoItConstants.au3"has the same variable define on line 157:Global Const $REG_QWORD = 11.
To resolve your issue just put a comment in front of line 20 in _Regfunc.au3 like the lines above it.

So initially do not compile the script, but run it will the full SciTE version and you will be told which line in which file has the issue.

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Yesterday afternoon I have installed autoit-v3-setup.exe and SciTE4AutoIt3.exe. Before that I was using the portable version of AutoIt.


I have compiled _RegFunc.au3 and the process went well.
Starting the executable show the same message showed in MyApp.

Some times it advice of error in line 530, other in line 519 (with the same comment).

Opening _RegFunc.au3 in Scite and executing the command Go (F5) show the following message:

>"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\Registry\_RegFunc.au3" /UserParams    
+>14:32:00 Starting AutoIt3Wrapper v.19.102.1901.0 SciTE v.4.1.2.0   Keyboard:00000410  OS:WIN_7/  CPU:X64 OS:X64  Environment(Language:0410)  CodePage:0  utf8.auto.check:4
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\Utente\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\Utente\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.14.5)  from:C:\Program Files (x86)\AutoIt3  input:C:\Registry\_RegFunc.au3
"C:\Registry\_RegFunc.au3"(20,29) : error: $REG_QWORD previously declared as a 'Const'.
Global Const $REG_QWORD = 11
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Registry\_RegFunc.au3 - 1 error(s), 0 warning(s)
!>14:32:00 AU3Check ended. Press F4 to jump to next error.rc:2
+>14:32:00 AutoIt3Wrapper Finished.
>Exit code: 2    Time: 2.234

I have followed every step, and after compiled script now the project works fine.

 

But a question is spontaneous... Why the line 20 is not stopped by default?
(I can understand you know already the solution...).

Thanks.

 

Have you noticed I grow every time? And it's only the third day!!!  :P

 

If you are interested, in forum.masterdrive.it they have the same emoticons you use, but bigger and animated. take a look...

Link to comment
Share on other sites

Comment out or delete the line "Global Const $REG_QWORD = 11" in _RegFunc.au3.  For future reference, you must realize that _RegFunc.au3 was written back in 2008 and AutoIt has changed somewhat in the past 10 years, in this case the variable "Global Const $REG_QWORD = 11" has now been declared in AutoItConstants.au3.  Generally speaking if your using old UDFs and a variable has already been declared as const, it means one of the includes or sub include udfs has already defined the variable and so you can safely comment out the variable (i.e. your UDF not the built-in AutoIt includes).  Personally I always double check that the variables have the same values as the udf, otherwise I'd need to rename the variable within the udf to something new.

So with that in mind, if you look at the includes at the top of _RegFunc.au3, there are two includes APIRegConstants.au3 and Constants.au3, $REG_QWORD is not declared in either of these, but if you look at the includes in Constants.au3 you'll find AutoItConstants.au3, this is where the $REG_QWORD = 11 was declared.

Hope that clears things up.

Link to comment
Share on other sites

  • Developers
2 hours ago, Grof said:

But a question is spontaneous... Why the line 20 is not stopped by default?

Probably because some standard AutoIt3 includes are changed after this UDF came out. :) 

2 hours ago, Grof said:

I have compiled _RegFunc.au3 and the process went well.

That can't be the case when you have the full version of SciTE4AutOit3 installed as that would have given this ERROR as well!\

Either way: First test an script with RUN as much as possible to be able to better determine the issues as the compiled script contains one big script with all included files in there.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...