Show: Delphi C++
Display Preferences

Compiler Directives for Strings

From RAD Studio
Jump to: navigation, search

Go Up to Working with Strings


The following Delphi compiler directives affect character and string types.

Compiler Directives for Strings

Directive Description

{$H+/-}

A compiler directive, $H, controls whether the reserved word string represents a short string or a long string. In the default state, {$H+}, string represents a long string. You can change it to a ShortString by using the {$H-} directive.

{$P+/-}

The $P directive is meaningful only for code compiled in the {$H-} state, and is provided for backwards compatibility. $P controls the meaning of variable parameters declared using the string keyword in the {$H-} state. In the {$P-} state, variable parameters declared using the string keyword are normal variable parameters, but in the {$P+} state, they are open string parameters. Regardless of the setting of the $P directive, the OpenString identifier can always be used to declare open string parameters.

{$V+/-}

The $V directive controls type checking on short strings passed as variable parameters. In the {$V+} state, strict type checking is performed, requiring the formal and actual parameters to be of identical string types. In the {$V-} (relaxed) state, any short string type variable is allowed as an actual parameter, even if the declared maximum length is not the same as that of the formal parameter. Be aware that this could lead to memory corruption. For example: var S: string[3];.

procedure Test(var T: string);
begin
  T := '1234';
end;
begin
  Test(S);
end.

{$X+/-}

The {$X+} compiler directive enables support for null-terminated strings by activating the special rules that apply to the built-in PChar type and zero-based character arrays. (These rules allow zero-based arrays and character pointers to be used with Write, Writeln, Val, Assign, and Rename from the System unit.)

See Also

Personal tools
RAD Studio 10.2 Tokyo
In other languages
Previous Versions
Assistance