Groups | Search | Server Info | Login | Register


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

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:12 +0200
Message-ID <e2dbqcFkv7fU2@mid.individual.net> (permalink)
References <nprn44$mvb$1@dont-email.me> <1rco3b1rvcu6.1k5cho7qohwwc$.dlg@40tude.net> <nprp91$trt$1@dont-email.me>

Show all headers | View raw


P E Schoen schrieb:
> "JJ"  wrote in message news:1rco3b1rvcu6.1k5cho7qohwwc$.dlg@40tude.net...
> 
> [snip]
>> GetCurrentDirectory() arguments are: the buffer pointer, then the 
>> buffer length. Not the buffer length, then the buffer pointer.
> 
>  From the Delphi help:
> 
> DWORD GetCurrentDirectory(
> 
>    DWORD nBufferLength,    // size, in characters, of directory buffer
>    LPTSTR lpBuffer     // address of buffer for current directory
>   );

According to MSDN I'd think that the length comes first.

> Also, perhaps I could use the return value of the function with a buffer 
> size of zero. It would return the size needed, and then I could use 
> alloc() to create the memory space to use. I just don't know what is the 
> "best" way to handle functions like this, and I may have been using the 
> PChar() cast improperly.

Most API functions, dealing with variable amount of data, return the 
required size when called with a Nil pointer. MSDN also claims that the 
*required* size is returned by GetCurrentDirectory, if the string 
doesn't fit into the buffer, but I'd not rely on that. At least the call 
succeeded if the returned (actual) size is lower than the allocated size.

All non-empty dynamic Strings are automatically terminated by an 
invisible and not counted zero char. I.e. you can/should SetLength(str, 
charcount) to extend or shrink a dynamic String to the required length, 
with a zero byte at its end as expected by API (C) funtions.

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