GPC REFERENCE: SetLength
Hello, folks! Here is a sketch for a `SetLength' reference section. Dose somebody know whether this
@samp{SetLength} is a Borland Delphi 1.0 extension.
is really true? Yours, Peter -- Peter Gerwinski, Essen, Germany, http://home.pages.de/~Peter.Gerwinski/ Maintainer GNU Pascal - http://home.pages.de/~GNU-Pascal/ - gpc-980511 PGP key on request - 6C 94 45 BE 28 A4 96 - 0E CC E9 12 47 25 82 75 Fight the SPAM and UBE! - http://spam.abuse.net/ - http://maps.vix.com/ @c ---------------------------------------------------------------------------- @node SetLength @unnumberedsec SetLength @cindex SetLength @unnumberedsubsec Syntax @smallexample Procedure SetLength ( Var S: String; NewLength: Integer ); @end smallexample @unnumberedsubsec Description @samp{SetLength} explicitly assigns a new length @samp{NewLength} to the string parameter @code{S}. The contents of the string is @emph{not} changed; if the operation increases the length of the string, the characters appended at the end are @emph{undefined}. If you want to use @samp{SetLength}, please enable ``extended syntax'' (@samp{--extended-syntax} or @samp{(*$X+*)}). @unnumberedsubsec Standards @samp{SetLength} is a Borland Delphi 1.0 extension. @unnumberedsubsec Example @example Program TestSetLength; (*$X+*) (* Enable "dangerous" features *) Var S: String ( 26 ); begin S:= 'Hello, world!'; SetLength ( S, length ( 'Hello' ) ); writeln ( S ); (* 'Hello' *) SetLength ( S, 26 ); writeln ( S ); (* 'Hello, world!(%$@§"!"§$§"$' *) (* undefined characters ^^^^^^^^^^^^^ *) SetLength ( S, 42 ); (* The overflow is *not* (yet) detected *) writeln ( S ); (* This might cause a runtime error. *) end. @end example @unnumberedsubsec See also @ref{@ref{length}, @ref{String}, @ref{SetType}. @c ----------------------------------------------------------------------------
On Mon, 1 Jun 1998, Peter Gerwinski wrote:
Dose somebody know whether this
@samp{SetLength} is a Borland Delphi 1.0 extension. is really true?
It is definitely true of Delphi 2.0, I'm sure it's true of Delphi 1.0 as well since it's in the System Unit. Here's the text straight out of Delphi 2.0's help: Unit System Declaration procedure SetLength(var S: string; NewLength: Integer); Description The SetLength procedure sets the dynamic length of a string variable. For a short string variable, SetLength simply sets the length indicator character (the character at S[0]) to the given value. In this case, NewLength must be a value between 0 and 255. For a long string variable, SetLength reallocates the string referenced by S to the given new length. Any existing characters in the string are preserved, but the contents of any newly allocated space is undefined. If there is not enough memory available to reallocate the string, an EOutOfMemory exception is raised. Following a call to SetLength, S is guaranteed to reference a unique string, that is a string with a reference count of one. See ya! Orlando Llanes "Meine Damen und Herren, Elvis hat soeben das Gebaeude verlassen!" "Look out fo' flyeeng feet" O__/ a010111t@bc.seflin.org \/|____. O <__. \/\> / \ ____________|___\______ http://ourworld.compuserve.com/homepages/Monkey414
1-Jun-98 13:31 Peter Gerwinski wrote:
Dose somebody know whether this
@samp{SetLength} is a Borland Delphi 1.0 extension.
is really true?
AFAIK this function was introduced in Borland Delphi 2.0 to provide a compatible way to assign string length for various string types. Delphi 1.0 had only one string type (Borland Pascal style short strings) and didn't have such function. Yours, -- Marius Gedminas "A Hacker is any person who derives E-mail: mgedmin@pub.osf.lt joy from discovering ways to WWW: http://www-public.osf.lt/~mgedmin circumvent limitations." rab'86
According to Marius Gedminas:
@samp{SetLength} is a Borland Delphi 1.0 extension.
AFAIK this function was introduced in Borland Delphi 2.0 to provide a compatible way to assign string length for various string types. Delphi 1.0 had only one string type (Borland Pascal style short strings) and didn't have such function.
Okay, I corrected it to "a Borland Delphi 2.0 extension" (until further notice;-). Thanks. Peter -- Peter Gerwinski, Essen, Germany, http://home.pages.de/~Peter.Gerwinski/ Maintainer GNU Pascal - http://home.pages.de/~GNU-Pascal/ - gpc-980511 PGP key on request - 6C 94 45 BE 28 A4 96 - 0E CC E9 12 47 25 82 75 Fight the SPAM and UBE! - http://spam.abuse.net/ - http://maps.vix.com/
participants (3)
-
Marius Gedminas -
Orlando Llanes -
Peter Gerwinski