2011-12-10 50 views
4

我已经下载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, 
    ..... 

[帕斯卡错误] IDEVirtualResources.pas(155):E2026常量表达式预期
[帕斯卡错误] IDEVirtualResources.pas(156):E2026常量表达式预期
[帕斯卡错误] IDEVirtualResources。 PAS(157):E2026常量表达式预期

更新
更改widestringstring停止编译器抱怨,(我怀疑它会在其他地方产生一些问题,因为宽字符串<>字符串)我想保留类型为widestring的常量。

+2

该代码可能适用于D2009 +,其中资源字符串是WideStrings。 –

+1

对于它的价值,D2009和D2010不会抱怨这一点。可能与Unicode有关。 WideStrings毕竟是Windows管理的UTF-16LE字符串...并且在D2009之前的资源串是AnsiStrings。 –

+0

我不得不说,我甚至觉得你甚至可以有一个类型为'WideString'的常量。它们是真正的'WideStrings'在运行时与COM分配器分配,还是只是指向以NULL结尾的WideChar数组? –

回答

4

正如Uwe在评论中指出的,在Unicode版本的Delphi中,resourcestring的类型为WideString。但是你使用的是预编码的Delphi,所以resourcestring只是AnsiString。这解释了编译错误。

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

所以,既然你坚持使用Unicode之前的Delphi,我猜你实际上并不需要翻译字符串。在这种情况下,请将const阵列的声明从WideString更改为string。碰巧,这个数组是由这段代码声明的,但从未涉及过。

相关问题