When you declare routines that
take short-string parameters, you cannot include length specifiers in the
parameter declarations. That is, the declaration
procedure
Check(S: string[20]);
// syntax error
causes a compilation error. But
type
TString20 = string[20];
procedure
Check(S: TString20);
is valid. The special identifier OpenString
can be used to declare routines that take short-string parameters of varying
length:
procedure
Check(S: OpenString);
When the {$H-} and {$P+}
compiler directives are both in effect, the reserved word string is
equivalent to OpenString in parameter declarations.
Short strings, OpenString, $H, and $P are supported for backward compatibility only. In new code, you can avoid these considerations by using long strings.
Procedures and functions: Overview
When you declare routines that take short-string parameters, you cannot include length specifiers in the parameter declarations. That is, the declaration
声明一个接受短串参数的例程时,不能在参数声明中包括长度说明。简言之,下面的声明
procedure
Check(S: string[20]);
//语法错误
将导致编译错误。而下面的声明
type
TString20 = string[20];
procedure
Check(S: TString20);
则是有效的。特殊的标识符OpenString可以用于声明接受不同长度短串参数的例程,例如
procedure
Check(S: OpenString);
当编译指示 {$H-} 和 {$P+} 都有效时,在参数声明中保留字string等价于OpenString。
短串、OpenString、$H 和 $P 等仅提供对向(旧版本)后兼容支持。在新的代码中,可以通过使用长串来避免这些考虑。