谁能说清楚字符串资源ResourceString和字符串常量的区别。请举例说明。

馮強 2002-08-23 02:56:39
在程序中,

ResourceString
ResString1='Hello';
ResString2='Word';

var
String1:String;

begin
String1:=ResString1+ResString2;

...
end;

和下面的代码没有任何区别,请问区别主要表现在什么地方。

Const
ResString1='Hello';
ResString2='Word';

var
String1:String;

begin
String1:=ResString1+ResString2;

...
end;
...全文
210 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
chechy 2002-08-24
  • 打赏
  • 举报
回复
CSDN真是毛病,这么晚了,还服务器忙。
chechy 2002-08-24
  • 打赏
  • 举报
回复
在程序中,没有任何区别。

真正的区别是编译器产生代码时的发生的。
如果是resourcestring,那么编译器将把其编译到资源文件中,
而如果是const,那么编译器则把它编译到代码的数据段中。
Delphi的Demos下有一个resExplorer,你看看编译的程序,就能找到相应的resourcestring,而无非找到const中string。
lance09 2002-08-24
  • 打赏
  • 举报
回复
愿闻其详
zhxfzhxf1 2002-08-24
  • 打赏
  • 举报
回复
up
madyak 2002-08-24
  • 打赏
  • 举报
回复
使用上没区别!
资源字符串,将来修改的话方便!
用字符串常量,必需重新编译才行!
……………………………………………………………………………………
:.--.-.::想要说些什么,却无从说起,想要说声爱你却被风吹散。如果大海
:( (  ):::能换回曾经的爱我用一生等待:: 
(_, \ ) ,_)::    |
:::-'--`--:::::::: ~~|   ,    \ _ /
::::::::::::::::::: ,|`-._/|  -== (_) ==-
::::::::^^::::::::.' |  /||\   /  \
::::::^^::::::::.'  | ./ ||`\    |
:::::::::::::::/ `-. |/._ || \
::::::::::::::|   ||  ||  \
~~=~_~^~ =~ \~~~~~~~'~~~~'~~~~/~~`` ~=~^~
~^^~~-=~^~ ^ `--------------'~^~=~^~_~^=~^~

……………………………………………………………………………………
oracle_lover 2002-08-24
  • 打赏
  • 举报
回复
Resource strings are stored as resources and linked into the executable or library so that they can be modified without recompiling the program...
Resource strings 作为资源被保存,并被连接到可执行文件和库文件,因此它们能在程序不重新编译的情况下被修改。

好处:方便软件发布的国际化。相同的软件携带不同的资源文件就可以了。


题外话:你在Delphi中的showmessage(), messageBox()... 按钮是'ok' 'cancel' ....标题是'confirm' 'warning' ... 怎么办?

随便新建一个Appication, 打开C:\Program Files\Borland\Delphi6\Source\Vcl\Consts.pas,看见什么了:resourcestring,改成中文;
编译生成consts.dcu,覆盖C:\Program Files\Borland\Delphi6\Lib\Consts.dcu。再showmessage()看看。

1,185

社区成员

发帖
与我相关
我的任务
社区描述
Delphi GAME,图形处理/多媒体
社区管理员
  • GAME,图形处理/多媒体社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧