【发布时间】:2019-02-01 09:55:58
【问题描述】:
我维护了一些在特定单元中使用 EmptyString 的相当古老的 Delphi 代码。
编译器将其解析为
costant EmptyString = '' - 来自 System.string
现在我的硬盘中没有 System.string.pas 文件或 .dcu,因此我无法了解更多信息。
我发现
C:\Program Files (x86)\Embarcadero\Studio\17.0\source\rtl\sys\system.SysUtils.pas
另一个类似的常数:
{ Empty string and null string pointer. These constants are provided for
backwards compatibility only. }
EmptyStr: string = '';
{$IFNDEF NEXTGEN}
NullStr: PString = @EmptyStr;
乍一看,EmptyStr 和 EmptyString 似乎只是在过去使用过,所以它们在某种程度上已弃用,因此最好直接使用 '' 或在应用程序中定义重新定义它们的常量.
现在升级第 3 方组件后,我意识到 EmptyString 不再解决。
我的问题是:
System.String 到底是什么?为什么rtl中没有对应的.pas文件?
我用谷歌搜索没有成功。
谢谢。
【问题讨论】:
-
我不记得读过
System.string但它可能只是Delphis 内置的string类型。相关代码部分在 System.pas 单元中,部分内置在编译器中。 -
System.string type 字符串in unit System。它不是类或任何东西,它是内置类型,是编译器的特殊类型,由运行时管理。这篇文章描述得好一点(连同 PChar):"PChars: no strings attached"。
-
@Uli:我有。您会在错误消息等(例如
Incompatible types: 'System.string' and 'System.Integer'或类似内容)和 RTTI 中看到它。