Groups | Search | Server Info | Login | Register


Groups > comp.lang.pascal.delphi.misc > #741

Re: Strings and PChar (D4 Pro)

From Hans-Peter Diettrich <DrDiettrich1@aol.com>
Newsgroups comp.lang.pascal.delphi.misc
Subject Re: Strings and PChar (D4 Pro)
Date 2016-08-27 13:41 +0200
Message-ID <e2dcm5Fl5mdU1@mid.individual.net> (permalink)
References <nprn44$mvb$1@dont-email.me> <nprogt$ri8$1@dont-email.me> <1bsilt045bp2t.1iu5ee8qm8nbn$.dlg@40tude.net>

Show all headers | View raw


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

Back to comp.lang.pascal.delphi.misc | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Strings and PChar (D4 Pro) "P E Schoen" <paul@pstech-inc.com> - 2016-08-27 05:39 -0400
  Re: Strings and PChar (D4 Pro) "P E Schoen" <paul@pstech-inc.com> - 2016-08-27 06:03 -0400
    Re: Strings and PChar (D4 Pro) "P E Schoen" <paul@pstech-inc.com> - 2016-08-27 06:28 -0400
    Re: Strings and PChar (D4 Pro) JJ <jj4public@vfemail.net> - 2016-08-27 18:00 +0700
      Re: Strings and PChar (D4 Pro) Hans-Peter Diettrich <DrDiettrich1@aol.com> - 2016-08-27 13:41 +0200
  Re: Strings and PChar (D4 Pro) JJ <jj4public@vfemail.net> - 2016-08-27 17:05 +0700
    Re: Strings and PChar (D4 Pro) "P E Schoen" <paul@pstech-inc.com> - 2016-08-27 06:15 -0400
      Re: Strings and PChar (D4 Pro) JJ <jj4public@vfemail.net> - 2016-08-27 18:09 +0700
      Re: Strings and PChar (D4 Pro) Hans-Peter Diettrich <DrDiettrich1@aol.com> - 2016-08-27 13:12 +0200
        Re: Strings and PChar (D4 Pro) "P E Schoen" <paul@pstech-inc.com> - 2016-08-27 18:59 -0400
  Re: Strings and PChar (D4 Pro) Hans-Peter Diettrich <DrDiettrich1@aol.com> - 2016-08-27 12:50 +0200

csiph-web