Board index » delphi » Long strings

Long strings

Quote
> I need to pass the long string as a parameter (buffer) to read
> via ReadFile. It works only this way:
>   SetLength(s, dwAvail);
>   ReadFile(hInputRead, Pointer(s)^, dwAvail, dwRead, nil);
> where s is the long string, however, I hate that typecast Pointer(s)^ . What
> would be the clean way of handling that ? I need the address of the buffer
> to be used as untyped variable.

There isn't a "clean" way. You *might* get it to work by writing
PChar(s) rather than Pointer(s)^, assuming Delphi's extended syntax
will automatically dereference the PChar (Haven't tried...). Apart
from that, you are manually bridging the gap between Delphi and the
Win32 API. How much cleaner *could* it get?

Chris.

 

Re:Long strings


PChar(s) doesn't work because compiler complains it cannot convert
const to variable. I think we have to be happy with Pointer(s)^ ...

Quote
Chris Rankin <RankinC{no.sp...@Logica.com> wrote:
>> I need to pass the long string as a parameter (buffer) to read
>> via ReadFile. It works only this way:
>>   SetLength(s, dwAvail);
>>   ReadFile(hInputRead, Pointer(s)^, dwAvail, dwRead, nil);
>> where s is the long string, however, I hate that typecast Pointer(s)^ . What
>> would be the clean way of handling that ? I need the address of the buffer
>> to be used as untyped variable.
>There isn't a "clean" way. You *might* get it to work by writing
>PChar(s) rather than Pointer(s)^, assuming Delphi's extended syntax
>will automatically dereference the PChar (Haven't tried...). Apart
>from that, you are manually bridging the gap between Delphi and the
>Win32 API. How much cleaner *could* it get?
>Chris.

Lester

lko...@ottawa.com
http://www.{*word*104}us.ca/~lkovac/lester.htm

Other Threads