Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
873 views
in Technique[技术] by (71.8m points)

delphi - Is there some advantage in use resourcestring instead of a const string?

Would you tell me if there is some advantage (less sotorage space, increase speed, etc) in using:

resourcestring
    MsgErrInvalidInputRange = 'Invalid Message Here!';

instead of

const
    MsgErrInvalidInputRange : String = 'Invalid Message Here!';
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The const option will be faster than resourcestring, because the later will call the Windows API to get the resource text. You can make it faster by using some caching mechanism. This is what we do in our Enhanced Delphi RTL.

And it's a good idea to first load the resourcestring into a string, if you'll have to access many times to a resourcestring content.

The main point of resourcestring is to allow i18n (internationalization) of your program.

You've got the Translation Manager with some editions of the Delphi IDE. But it relies on external DLL.

You can use the gettext system, coming from the Linux world, from http://dxgettext.po.dk which relies on external .po files.

We included our own i18n mechanism in our framework, which translates and caches the resourcestring text, and relies on external .txt files (you can use UTF-8 or Unicode text files, from Delphi 6 up to XE). The caching make it quite as fast as the const usage. See http://synopse.info/fossil/finfo?name=SQLite3/SQLite3i18n.pas

There are other open source or commercial solutions around.

About size storage, resourcestring are stored as UC2 buffers. So resourcestring will use more memory than string up to Delphi 2009. Since Delphi 2009, all string are unicodestring i.e. UCS2, so you won't have much more storage size. In all cases, storage size of text is not the bigger size parameter for an application (bitmaps and code size have a much bigger effect to the final exe).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...