Originale-mail to me for new edition

 

String parameters

 

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.

 

Topic groups

 

See also

About string types

Parameters: Overview

Procedures and functions: Overview

Short strings

 

 

译文

 

串参数

 

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 等仅提供对向(旧版本)后兼容支持。在新的代码中,可以通过使用长串来避免这些考虑。

 

主题组

 

相关主题

关于串类型

参数:概述

过程和函数:概述

短串