[fpc-pascal] Copying a Pchar to an array of bytes

Alexander Grotewohl alex at dcclost.com
Tue May 19 19:28:08 CEST 2020


I believe pchar has special treatment where pchar[i] is the same as pchar^[i]

do move(Hello^, ...

--
Alexander Grotewohl
https://dcclost.com

________________________________
From: fpc-pascal <fpc-pascal-bounces at lists.freepascal.org> on behalf of Giuliano Colla <giuliano.colla at fastwebnet.it>
Sent: Tuesday, May 19, 2020 1:05:54 PM
To: FPC-Pascal users discussions <fpc-pascal at lists.freepascal.org>
Subject: [fpc-pascal] Copying a Pchar to an array of bytes

I'm not too familiar with Pchar, and apparently I'm missing something.

I have a Pchar string which I must copy into an array of bytes.

Could someone explain me while a move doesn't work while an assignment
byte by byte does?

Here's a snippet of the code:

buffer: array [0..1023] of byte;
Hello: PChar = 'Hello from server';
....
   len := strlen(Hello);
----
Move(Hello,buffer,len); <--- Garbage in buffer - doesn't work
----
   for I := 0 to Pred(len) do
   begin
     buffer[I] := Byte(Hello[I]);  <---- Works just fine.
   end;

I fail to understand why. What I'm missing?

Giuliano

--
Do not do to others as you would have them do to you.They might have different tastes.

_______________________________________________
fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20200519/bbb61565/attachment.htm>


More information about the fpc-pascal mailing list