Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Hans-Peter Diettrich Newsgroups: comp.lang.pascal.delphi.misc Subject: Re: Strings and PChar (D4 Pro) Date: Sat, 27 Aug 2016 13:41:39 +0200 Lines: 32 Message-ID: References: <1bsilt045bp2t.1iu5ee8qm8nbn$.dlg@40tude.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net OK6+ZjQxOmCUYZmsSaZF9gIa7iCebJpk2iGYNcXGuWaMDEimUj Cancel-Lock: sha1:fMobdaL/fiNPU0ABBpjG+x1JHAw= User-Agent: Thunderbird 2.0.0.21 (Windows/20090302) In-Reply-To: <1bsilt045bp2t.1iu5ee8qm8nbn$.dlg@40tude.net> Xref: csiph.com comp.lang.pascal.delphi.misc:741 JJ schrieb: > String... > String type is a combination between ShortString and PChar (null terminated > string). The String storage layout is like ShortString except that the > string length is 16-bit instead of 8-bit. The data for "ABC" would be like > below. > > 03,00,41,42,43,00 > > i.e. > > (* > StringStorage = record > StringLength : Word; > StringData : Array [1..n] of Char; > end; > Where n is variable. i.e. variable field size > *) This is not true for 32 bit Delphi, which uses something close to Windows BSTR (OLE compatible). The pointer goes to the first character (fully compatible PCHAR), and before the characters the 32 bit size and reference count is stored. See managed data types in OH. When a ShortString is retyped into a dynamic String, the compiler usually mocks about many references to str[0], used to set and retrieve the used length of the ShortString. The Length and SetLength functions handle both string types, so that they allow to change string types without further changes to the existing code. DoDi