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-boun...@lists.freepascal.org> on behalf of 
Giuliano Colla <giuliano.co...@fastwebnet.it>
Sent: Tuesday, May 19, 2020 1:05:54 PM
To: FPC-Pascal users discussions <fpc-pascal@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@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to