[fpc-pascal] pchar with more than 255 characters

Felipe Monteiro de Carvalho felipemonteiro.carvalho at gmail.com
Mon Nov 14 22:08:51 CET 2011


On Sun, Nov 13, 2011 at 1:39 AM, Rainer Stratmann
<RainerStratmann at t-online.de> wrote:
> procedure getchars( p : pchar );
> var l : longint;
> begin
>  l := length( p );
> end;

You cannot do length in a PChar, it has no length information. I think
this code is probably automatically converting the PChar to a Pascal
String and then after that calling Length in the Pascal String, so
your code is not very efficient.

Pass the length of the PChar in an aditional parameter instead. Or
write a routine which will count until the first #0 of the PChar to
see how many characters it has.

-- 
Felipe Monteiro de Carvalho



More information about the fpc-pascal mailing list