Why can't I use resourcestring as a constant?

I downloaded embtvstools (Embarcadero TVirtualShellTools) from: http://embtvstools.svn.sourceforge.net/

However, when I create a new package, drop the .pas files (and the missing compilers.inc from VirtualTreeView in) and compile the lot, I get error E2026 , why is this and how can I avoid / workaround?

 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 Expected constant expression [Pascal error] IDEVirtualResources.pas (156): E2026 Expected constant expression [Pascal error] IDEVirtualResources.pas (157): E2026 Expected constant expression

Update
Changing widestring to string stops the compiler complaining (I suspect it will create some problem elsewhere because widestring <> string) I would like to keep a constant like widestring .

+4
source share
1 answer

As Uwe points out in the comments, resourcestring in Unicode versions of Delphi are of type WideString . But you are using pre-Unicode Delphi, so resourcestring just AnsiString . This explains the compilation error.

How to act depends on what you are trying to do. If you intend to translate these lines into different languages, then you may be bound. If you intend to do this, then obviously you will be much better off with the Unicode version of Delphi.

So, since you are sticking with pre-Unicode Delphi, I think you really don't need to translate strings. In this 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 mentioned.

+4
source

Source: https://habr.com/ru/post/1385655/


All Articles