Re: [fpc-pascal] pchar with more than 255 characters
On Tue, Nov 15, 2011 at 11:33 AM, Jonas Maebe jonas.ma...@elis.ugent.be wrote: length(pchar) is translated into strlen(pchar) (just like in Delphi). But why is it limited to 255 chars in {$H-} ? (I understood that it is limited like this from the original poster) I don't see anything about this in the docs: http://www.freepascal.org/docs-html/rtl/strings/strlen.html -- Felipe Monteiro de Carvalho ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] pchar with more than 255 characters
Am 16.11.2011 17:15, schrieb Felipe Monteiro de Carvalho: On Tue, Nov 15, 2011 at 11:33 AM, Jonas Maebejonas.ma...@elis.ugent.be wrote: length(pchar) is translated into strlen(pchar) (just like in Delphi). But why is it limited to 255 chars in {$H-} ? (I understood that it is limited like this from the original poster) If you look at the call the original poster sent, you will see why: For example: getchars( '12345 ... 255256257258' + '1234567213939873987' + ... ... '1234567213939873987'); // more than 255 chars FPC converts the constant string to the current generic string type which is String[255] in case of {$H-} and not AnsiString. Thus the string will appear truncated after 255 characters. Regards, Sven ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] pchar with more than 255 characters
On 16 Nov 2011, at 17:15, Felipe Monteiro de Carvalho wrote: On Tue, Nov 15, 2011 at 11:33 AM, Jonas Maebe jonas.ma...@elis.ugent.be wrote: length(pchar) is translated into strlen(pchar) (just like in Delphi). But why is it limited to 255 chars in {$H-} ? It is not. (I understood that it is limited like this from the original poster) The original poster said that he could not use string constants longer than 255 characters in his code in {$h-} mode. Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] pchar with more than 255 characters
Am Wednesday 16 November 2011 17:15:51 schrieb Felipe Monteiro de Carvalho: On Tue, Nov 15, 2011 at 11:33 AM, Jonas Maebe jonas.ma...@elis.ugent.be wrote: length(pchar) is translated into strlen(pchar) (just like in Delphi). But why is it limited to 255 chars in {$H-} ? (I understood that it is limited like this from the original poster) Exactly. Why? Now I changed all string vars (aprox. 1250) to shortstring and the string[..] vars remain the same as before. So now I can remove the swith -Sh- from additional compiler arguments/flags. And now it is possible again (like in the compiler versions before) to put more than 255 chars incombination with a pchar. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] pchar with more than 255 characters
On 14 Nov 2011, at 22:08, Felipe Monteiro de Carvalho wrote: On Sun, Nov 13, 2011 at 1:39 AM, Rainer Stratmann rainerstratm...@t-online.de wrote: procedure getchars( p : pchar ); var l : longint; begin l := length( p ); end; You cannot do length in a PChar length(pchar) is translated into strlen(pchar) (just like in Delphi). Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] pchar with more than 255 characters
On Sun, Nov 13, 2011 at 1:39 AM, Rainer Stratmann rainerstratm...@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 ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal