Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
896 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 Answer

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...