为什么我不能使用资源字符串作为常量?

发布于 2024-12-20 19:25:43 字数 1233 浏览 2 评论 0原文

我从以下位置下载了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

若水微香 2024-12-27 19:25:43

正如 Uwe 在评论中指出的那样,Delphi Unicode 版本中的 resourcestringWideString 类型。但您使用的是 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 type WideString. But you are using pre-Unicode Delphi and so resourcestring is simply AnsiString. 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 from WideString to string. As it happens, this array is declared by this code but never once referred to.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文