使用resourcestring而不是一个const字符串有什么优势吗? [英] Is there some advantage in use resourcestring instead of a const string?

查看:130
本文介绍了使用resourcestring而不是一个const字符串有什么优势吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  resourcestring你是否会告诉我是否有一些优势(减少sotorage空间,增加速度等) 
MsgErrInvalidInputRange ='Invalid Message Here!';

而不是

 code> const 
MsgErrInvalidInputRange:String ='Invalid Message Here!';


解决方案

const选项将比resourcestring快,因为稍后将调用Windows API获取资源文本。
您可以使用一些缓存机制来加快速度。这就是我们在增强型Delphi RTL中所做的工作。



最好先将资源重新加载到一个字符串中,如果你必须访问多次资源优惠的内容。



资源的重点是允许您的程序的i18n(国际化)。



你有一些版本的Delphi IDE的翻译经理。但是它依赖于外部DLL。



您可以使用来自Linux世界的gettext系统,从 http://dxgettext.po.dk ,它依赖于外部.po文件。



我们将自己的i18n机制我们的框架,它翻译和缓存resourcestring文本,并依赖外部.txt文件(您可以使用UTF-8或Unicode文本文件,从Delphi 6到XE)。缓存使得它与const的使用相当快。请参阅 http://synopse.info/fossil/finfo?name=SQLite3/SQLite3i18n。 pas



有其他开源或商业解决方案。



关于大小存储,资源存储为UC2缓冲区。所以resourcestring会比Delphi 2009使用更多的内存。由于Delphi 2009,所有的字符串都是unicodestring,即UCS2,所以你不会有更多的存储空间。在所有情况下,文本的存储大小不是应用程序的较大尺寸参数(位图和代码大小对最终的exe有更大的影响)。


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!';

解决方案

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

这篇关于使用resourcestring而不是一个const字符串有什么优势吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆