smooth 发表于 2014-2-11 10:01:17

IsDeclared无法检查变量是否已经声明

本帖最后由 smooth 于 2014-2-11 10:04 编辑

我脚本用先插入#include <WindowsConstants.au3>这个头文件,其中里面声明了4个变量:

Global Const $WM_COMMAND = 0x0111
Global Const $WM_MOVE = 0x0003
Global Const $WM_LBUTTONDOWN = 0x0201
Global Const $WM_RBUTTONDOWN = 0x0204

在WindowsConstants.au3的后面,还插入了GUIInputSetOnlyNumbers.au3这个头文件,其中声明了上述4个变量,不过声明的方式如下:

If Not IsDeclared("WM_COMMAND")                 Then Global Const $WM_COMMAND                = 0x0111
If Not IsDeclared("WM_MOVE")                        Then Global Const $WM_MOVE               = 0x0003
If Not IsDeclared("WM_LBUTTONDOWN")         Then Global Const $WM_LBUTTONDOWN         = 0x0201
If Not IsDeclared("WM_RBUTTONDOWN")         Then Global Const $WM_RBUTTONDOWN         = 0x0204


查了一下IsDeclared函数的作用,是检查某个变量是否已经声明过了,没声明过的话则声明某个变量。可是虽然如此,我的脚本还是无法执行,提示如下错误信息:
D:\Program Files\autoit3\Include\GUIInputSetOnlyNumbers.au3(4,74) : ERROR: $WM_COMMAND previously declared as a 'Const'
If Not IsDeclared("WM_COMMAND")                 Then Global Const $WM_COMMAND                = 0x0111
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                ~~~~~~~~^
D:\Program Files\autoit3\Include\GUIInputSetOnlyNumbers.au3(5,70) : ERROR: $WM_MOVE previously declared as a 'Const'
If Not IsDeclared("WM_MOVE")                        Then Global Const $WM_MOVE                         = 0x0003
~~~~~~~~~~~~~~~~~~~~~~~~~~~~                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~                        ~~~~~~~~^
D:\Program Files\autoit3\Include\GUIInputSetOnlyNumbers.au3(6,81) : ERROR: $WM_LBUTTONDOWN previously declared as a 'Const'
If Not IsDeclared("WM_LBUTTONDOWN")         Then Global Const $WM_LBUTTONDOWN         = 0x0201
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~        ~~~~~~~~^
D:\Program Files\autoit3\Include\GUIInputSetOnlyNumbers.au3(7,81) : ERROR: $WM_RBUTTONDOWN previously declared as a 'Const'
If Not IsDeclared("WM_RBUTTONDOWN")         Then Global Const $WM_RBUTTONDOWN         = 0x0204
这究竟是为什么呢?如果在插入头文件的顺序上,是先插入GUIInputSetOnlyNumbers.au3,再插入WindowsConstants.au3,那提示错误好像还好理解。
谢谢!

afan 发表于 2014-2-11 10:49:52

AU3Check.exe 对 IsDeclared 类函数不会识别,可以无视之。

netegg 发表于 2014-2-11 11:22:52

看英文,已经声明为全局常量了,不能重新声明

zhouflye 发表于 2014-2-11 12:48:19

好东东,学习了!{:face (270):}

smooth 发表于 2014-2-11 16:51:22

回复 2# afan
原来如此,谢谢!
页: [1]
查看完整版本: IsDeclared无法检查变量是否已经声明