Name
OpenString Type
Syntax
Subroutine declaration(...; var Param: OpenString; ...);Description
OpenString declarations are let you pass a
ShortString argument to a subroutine when the
subroutine does not know the exact string size. Ordinarily, a
var string parameter’s type must match
exactly with an actual argument’s type. In the case of short
strings, the maximum string length is part of the type and must
match, to ensure that the subroutine does not try to store more
characters in the string than can fit.
An OpenString parameter relaxes the restriction
and lets you pass any size string to the subroutine. Delphi passes an
additional, hidden parameter that contains the maximum string size.
References to Param in the subroutine, therefore,
are type safe.
Tips and Tricks
The
$OpenStringscompiler directive makesvarShortStringparameters behave asOpenStringparameters. This directive is enabled by default. The only time you need to declare a parameter as typeOpenStringis when you are disabling the$OpenStringscompiler directive.If you disable the
$LongStringscompiler directive, thestringtype is a short string, sovarstringparameters are likeOpenString(unless you also disable the$OpenStringscompiler directive).If you are using long strings, you have no need for
OpenStringparameters.
See Also
| AnsiString Type, ShortString Type, String Keyword, Var Keyword, $H Compiler Directive, $LongStrings Compiler Directive, $OpenStrings Compiler Directive, $P Compiler Directive |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access