Groups | Search | Server Info | Login | Register


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

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 12:50 +0200
Message-ID <e2dbq4Fkv7fU1@mid.individual.net> (permalink)
References <nprn44$mvb$1@dont-email.me>

Show all headers | View raw


P E Schoen schrieb:
> This is probably a very basic question, but I may have been improperly 
> casting a string to PChar in some cases. For instance, I got the 
> following code to work as shown:
> 
> ====================================================
> procedure TfmOrtDatabase.btBackupClick(Sender: TObject);
> var       udfn: OrtData.TUserDataFile;
>          S, dbFileName, saveFileName, dirName: String;
> //          currDir: String;
>          currDir: array[0..50] of Char;
> begin
>  if Application.MessageBox( 'Backup Database Files?',
>         'Backup', MB_YESNO ) = ID_YES then begin //1
> //    currDir := '01234567890123456789012345678901234567890123456789';
> //    SetLength(currDir,50);
>    GetCurrentDirectory(sizeof(currDir)+1, @currDir);

Unlike a fixed size ShortString, a dynamic string variable is a pointer 
to a dynamically allocated char array. I'd guess that sizeof(currDir) 
will return 4, the size of a pointer. Try Length instead, which returns 
the current (allocated) size of the string. Also use PCHAR(currDir) to 
get a pointer to the payload, not to the pointer variable.

DoDi

Back to comp.lang.pascal.delphi.misc | Previous | NextPrevious 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