为什么我不能使用资源字符串作为常量?
我从以下位置下载了 embtvstools
(Embarcadero TVirtualShellTools):http://embtvstools.svn。 sourceforge.net/
但是,当我创建新包时,删除 .pas 文件(以及缺少的compilers.inc
(来自 VirtualTreeView) 并编译了很多,我收到错误 E2026,这是为什么以及如何避免/解决这个问题?
resourcestring
sAssociationChanged = 'Association Changed';
sItemCreate = 'Item Create';
sItemDelete = 'Item Delete';
....
const
// Literal translations of TShellNotifyEvent type. Useful when using the
// OnShellNotify event to print out what event occurred. VirtualShellUtilities.pas
// has a helper function ShellNotifyEventToStr that uses these.
VET_NOTIFY_EVENTS: array[0..19] of WideString = (
sAssociationChanged,
sAttributes,
sItemCreate,
.....
[Pascal 错误] IDVirtualResources.pas(155): E2026 需要常量表达式
[Pascal 错误] IDVirtualResources.pas(156): E2026 需要常量表达式
[Pascal 错误] IDVirtualResources.pas(157): E2026 需要常量表达式
更新
将 widestring
更改为 string
会阻止编译器抱怨,(我怀疑它会在其他地方产生一些问题,因为 Widestring <> string)我想保持常量输入宽字符串
。
I've downloaded embtvstools
(Embarcadero TVirtualShellTools) from: http://embtvstools.svn.sourceforge.net/
However when I create a new package, drop the .pas files (and a missing compilers.inc
from VirtualTreeView in) and compile the lot, I get an error E2026, why is this and how do I avoid/workaround this?
resourcestring
sAssociationChanged = 'Association Changed';
sItemCreate = 'Item Create';
sItemDelete = 'Item Delete';
....
const
// Literal translations of TShellNotifyEvent type. Useful when using the
// OnShellNotify event to print out what event occurred. VirtualShellUtilities.pas
// has a helper function ShellNotifyEventToStr that uses these.
VET_NOTIFY_EVENTS: array[0..19] of WideString = (
sAssociationChanged,
sAttributes,
sItemCreate,
.....
[Pascal Error] IDEVirtualResources.pas(155): E2026 Constant expression expected
[Pascal Error] IDEVirtualResources.pas(156): E2026 Constant expression expected
[Pascal Error] IDEVirtualResources.pas(157): E2026 Constant expression expected
Update
Changing the widestring
to a string
stops the compiler complaining, (I suspect it will create some issue elsewhere because widestring <> string) I would like to keep the constant of type widestring
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如 Uwe 在评论中指出的那样,Delphi Unicode 版本中的
resourcestring
是WideString
类型。但您使用的是 Unicode 之前的 Delphi,因此resourcestring
只是AnsiString
。这解释了编译错误。如何继续取决于您想要做什么。如果您打算将这些字符串翻译成不同的语言,那么您可能会陷入困境。如果您打算这样做,那么使用 Unicode 版本的 Delphi 显然会更好。
所以,既然你坚持使用 Unicode 之前的 Delphi,我想你实际上不需要翻译字符串。在这种情况下,只需将
const
数组的声明从WideString
更改为string
即可。碰巧的是,这个数组是由这段代码声明的,但从未被引用过。As Uwe points out in the comments,
resourcestring
in Unicode versions of Delphi is of typeWideString
. But you are using pre-Unicode Delphi and soresourcestring
is simplyAnsiString
. This explains the compilation error.How to proceed depends on what you are attempting to do. If you intend to translate these strings into different languages then you may be in a bind. If you are intending to do that then you would obviously be far better off with a Unicode version of Delphi.
So, since you are sticking with a pre-Unicode Delphi I guess you don't actually need to translate the strings. In which case just change the declaration of the
const
array fromWideString
tostring
. As it happens, this array is declared by this code but never once referred to.