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

标签 delphi delphi-2007

我已经从以下位置下载了 embtvstools (Embarcadero TVirtualShellTools):http://embtvstools.svn.sourceforge.net/

但是,当我创建新包时,删除 .pas 文件(以及 VirtualTreeView 中缺少的 compilers.inc)并编译该文件,我收到错误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 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

更新
widestring 更改为 string 会阻止编译器提示,(我怀疑它会在其他地方产生一些问题,因为 Widestring <> string)我想保留类型 宽字符串

最佳答案

正如 Uwe 在评论中指出的那样,Delphi Unicode 版本中的 resourcestringWideString 类型。但您使用的是 Unicode 之前的 Delphi,因此 resourcestring 只是 AnsiString。这解释了编译错误。

如何继续取决于您尝试执行的操作。如果您打算将这些字符串翻译成不同的语言,那么您可能会陷入困境。如果您打算这样做,那么使用 Unicode 版本的 Delphi 显然会更好。

所以,既然你坚持使用 Unicode 之前的 Delphi,我想你实际上并不需要翻译字符串。在这种情况下,只需将 const 数组的声明从 WideString 更改为 string 即可。事实上,这个数组是由这段代码声明的,但从未被引用过。

关于delphi - 为什么我不能使用资源字符串作为常量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8457253/

相关文章:

delphi - 在TButtonGroup.ButtonOptions中添加gboGroupStyle有什么作用?

delphi - 为什么我的图标在带有 TTrayIcon 的托盘栏上很难看?

delphi - 如何使用 FormatDateTime 返回与当前年份连接的默认日期?

delphi - IDE:结构查看器显示所有展开的项目

delphi - Delphi 2007 中的动画 GIF 和 TDrawgrid

delphi - StrToDate 不使用我的 FormatSetting

delphi - 这个无效指针在哪里?

c - 将 C .obj 文件链接到 Delphi 应用程序,解析标准 C 依赖项

sql - 搜索多个列表以查找缺失的条目

multithreading - 如何终止具有单独消息循环的线程?