Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2016-06

strcat problem

22 messages · 8 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Koenraad Lelong

Hi,

I used strcat to make a long PChar.
On my OpenSuse-box this works fine. On the RaspberryPi, is gives a runtime error 216.
Any suggestions what could be the problem ?

This part of the code :
cTekst:=#13'Now is the winter of our discontent'#13; cTekst:=StrCat(cTekst,'Made glorious summer by this sun of York;'#13); <-- here is the RT-error 216.
I have several more lines

Any work-around ? I actually need a long nul-teminated constant string of about 550 characters. I could write the whole string on one line, but I would like to prevent that. I prefer it like the C-code : "\n\
Now is the winter of our discontent\n\
Made glorious summer by this sun of York;\n\
And all the clouds that lour'd upon our house\n\
...

FWIW, I'm porting pigpio. The test-application x_pigpiod_if2 works mostly fine remotely (from my OpenSuse-box), but now I get this problem when testing the local version, i.e. on the pi itself.

Thanks,

Koenraad

Reply by email

David W Noon
to Koenraad Lelong

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Thu, 23 Jun 2016 16:06:45 +0200, Koenraad Lelong () wrote about "[Lazarus] strcat problem" (in
):

[snip]

cTekst:=#13'Now is the winter of our discontent'#13;

You need a trailing #0 byte on the end.

- --
Regards,

Dave [RLU #314465]
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* (David W Noon)
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iEYEARECAAYFAldr+RoACgkQogYgcI4W/5QnwwCfTxrsHYVew6YAxDGoEv4IfzTm DTMAn3i4G+K8F9d9Vpznyo15G7kdIoc7
=FMiY
-----END PGP SIGNATURE-----

Reply by email

Koenraad Lelong
to David W Noon

Op 23-06-16 om 16:58 schreef David W Noon:

Show quoted text 5 lines
[snip] > cTekst:=#13'Now is the winter of our discontent'#13; You need a trailing #0 byte on the end.
The definition of cTekst :
var
    cTekst : PChar;

So the compiler knows cTekst is a 0-terminated string doesn't, it ? And StrCat needs two parameters : PChar and PChar. So I think the compiler knows the strings are zero-terminated.
Besides, on my OpenSuse-box it works, or is that by chance ?

Koenraad.

Reply by email

Koenraad Lelong
to Koenraad Lelong

Op 23-06-16 om 21:08 schreef Koenraad Lelong:

Show quoted text 18 lines
Op 23-06-16 om 16:58 schreef David W Noon: > [snip] >> cTekst:=#13'Now is the winter of our discontent'#13; > > You need a trailing #0 byte on the end. > The definition of cTekst : var cTekst : PChar; So the compiler knows cTekst is a 0-terminated string doesn't, it ? And StrCat needs two parameters : PChar and PChar. So I think the compiler knows the strings are zero-terminated. Besides, on my OpenSuse-box it works, or is that by chance ? Koenraad.

Extra info :
I checked with a hex-dumper (executables for opensuse & pi). All strings end with a #0. No byte-count in front of them. All start at a longword-boundary.

Koenraad

Reply by email

Martin Grajcar
to Koenraad Lelong

Have you checked if there's any room behind #13'Now is the winter of our discontent'#13, so that someone else's memory won't get overwritten? I'd bet, there's none.

*Appends a copy of the source string to the destination string. The terminating null character in destination is overwritten by the first character of source, and a null-character is included at the end of the new string formed by the concatenation of both in destination.*

You'd need something like
SetLength(cTekst, enoughToHoldThemAll);
and maybe also
cTekst[oldLength] := #0;
before the very first strcat.

Koenraad Lelong wrote 37 lines
Op 23-06-16 om 21:08 schreef Koenraad Lelong: > Op 23-06-16 om 16:58 schreef David W Noon: > >> [snip] >> >>> cTekst:=#13'Now is the winter of our discontent'#13; >>> >> >> You need a trailing #0 byte on the end. >> >> > The definition of cTekst : > var > cTekst : PChar; > > So the compiler knows cTekst is a 0-terminated string doesn't, it ? > And StrCat needs two parameters : PChar and PChar. So I think the > compiler knows the strings are zero-terminated. > Besides, on my OpenSuse-box it works, or is that by chance ? > > Koenraad. > > Extra info : I checked with a hex-dumper (executables for opensuse & pi). All strings end with a #0. No byte-count in front of them. All start at a longword-boundary. Koenraad -- _______________________________________________ Lazarus mailing list http://lists.lazarus-ide.org/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20160623/bc2b3425/attachment.html>

Reply by email

David W Noon
to Koenraad Lelong: Op 23-06-16 om 16:58 schreef David W Noon: The definition of cTekst : var cTekst : PChar;…

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Thu, 23 Jun 2016 21:08:14 +0200, Koenraad Lelong () wrote about "Re: [Lazarus] strcat problem"
(in ):

Show quoted text 11 lines
Op 23-06-16 om 16:58 schreef David W Noon: > [snip] >> cTekst:=#13'Now is the winter of our discontent'#13; > > You need a trailing #0 byte on the end. > The definition of cTekst : var cTekst : PChar; So the compiler knows cTekst is a 0-terminated string doesn't, it ?

The cTekst variable is actually a pointer.

It's the string literal that needs the trailing NUL byte.

Moreover, assigning to a pointer typically modifies the address, rather than copying new text into the buffer. The idiomatic C function for this is strcpy().

And StrCat needs two parameters : PChar and PChar. So I think the compiler knows the strings are zero-terminated.

I think both literals need a trailing NUL.

The compiler probably knows nothing about StrCat() besides that it takes 2 pointers as parameters. It is the RTL that expects to receive NUL-terminated strings as arguments.

Besides, on my OpenSuse-box it works, or is that by chance ?

It could be that the data segment is initialized to binary zeroes on the Intel/AMD processor and left as junk on the ARM processor. This could be an artefact of the binutils on the different hardware platforms, as the ARM binaries might be sparsely defined in the executable, whereas the Intel binaries can be padded with zeroes.
- --
Regards,

Dave [RLU #314465]
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* (David W Noon)
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iEYEARECAAYFAldsO0QACgkQogYgcI4W/5Q+WQCff6iFNMJKXnlHWVqpSPih6l7f xFwAn0f/girIusmXB36FTzCfTGSiAta+
=zuH4
-----END PGP SIGNATURE-----

Reply by email

José Mejuto
to Koenraad Lelong: Op 23-06-16 om 16:58 schreef David W Noon: The definition of cTekst : var cTekst : PChar;…
Koenraad Lelong wrote 15 lines
Op 23-06-16 om 16:58 schreef David W Noon: > [snip] >> cTekst:=#13'Now is the winter of our discontent'#13; > > You need a trailing #0 byte on the end. > The definition of cTekst : var cTekst : PChar; So the compiler knows cTekst is a 0-terminated string doesn't, it ? And StrCat needs two parameters : PChar and PChar. So I think the compiler knows the strings are zero-terminated. Besides, on my OpenSuse-box it works, or is that by chance ?

Hello,

Did you allocated the memory for the pchar ? Did you allocated memory enough in target pchar to hold the large string after the strcat's ?

This code sample is wrong:

cTekst:=#13'text'#13;
strcat(cTekst,'other string');

The first assigns pchar to a read only memory block at compile time, and at runtime next bytes (not allocated) are overwritten with "other string" which will SIGSEGV for sure.

Reply by email

Sven Barth
to David W Noon: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Thu, 23 Jun 2016 21:08:14 +0200,…
"David W Noon" wrote 15 lines
> Op 23-06-16 om 16:58 schreef David W Noon: >> [snip] >>> cTekst:=#13'Now is the winter of our discontent'#13; >> >> You need a trailing #0 byte on the end. >> > > The definition of cTekst : var cTekst : PChar; > > So the compiler knows cTekst is a 0-terminated string doesn't, it > ? The cTekst variable is actually a pointer. It's the string literal that needs the trailing NUL byte.

The compiler guarantees that constant strings are NUL terminated. This is needed for easy conversion to PChar.

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20160624/6079429c/attachment.html>

Reply by email

Koenraad Lelong
to Martin Grajcar: Have you checked if there's any room behind #13'Now is the winter of our discontent'#13,…

Op 23-06-16 om 21:38 schreef Martin Grajcar:

Show quoted text 15 lines
Have you checked if there's any room behind #13'Now is the winter of our discontent'#13, so that someone else's memory won't get overwritten? I'd bet, there's none. /Appends a copy of the source string to the destination string. The terminating null character in destination is overwritten by the first character of source, and a null-character is included at the end of the new string formed by the concatenation of both *in destination*./ You'd need something like SetLength(cTekst, enoughToHoldThemAll); and maybe also cTekst[oldLength] := #0; before the very first strcat.

Updated my code :

  cTekst:=StrAlloc(600);
  cTekst:=#13'Now is the winter of our discontent'#13;
  cTekst:=StrCat(cTekst,'Made glorious summer by this sun of York;'#13);
  ...

cTekst is still a PChar.

Same problem : on the pi the program crashes on the first StrCat with a 216 error.

An extra error, now on my OpenSuse-box :
I finally do
StrDispose(cTekst);
And then the application crashes with a 216 error. Leaving that StrDispose out it runs fine, but then there's a memory-leak.

FWIW, I'm using FPC 2.6.5 (SVN version 49333M) on OpenSuse and 3.0.0 on the pi.

Koenraad

Reply by email

Yann Mérignac
to Koenraad Lelong
1 cTekst:=StrAlloc(600);
2 cTekst:=#13'Now is the winter of our discontent'#13;
3 cTekst:=StrCat(cTekst,'Made glorious summer by this sun of York;'#13);

On line 2 you change the value of cTekst and lose the memory allocated by StrAlloc. What you want to do is to copy the string constant value in the allocated memory with StrCopy or StrMove. See
http://www.freepascal.org/docs-html/rtl/strings/strcat.html

Another solution:

var
  S : String;
  cTekst : PChar;
begin
   S := #13'Now is the winter of our discontent'#13;
   S := S + 'Made glorious summer by this sun of York;'#13;
   cTekst := @S[1];
end;

2016-06-24 9:43 GMT+02:00 Koenraad Lelong :

Show quoted text 46 lines
Op 23-06-16 om 21:38 schreef Martin Grajcar: > Have you checked if there's any room behind #13'Now is the winter of our > discontent'#13, so that someone else's memory won't get overwritten? I'd > bet, there's none. > > /Appends a copy of the source string to the destination string. The > terminating null character in destination is overwritten by the first > character of source, and a null-character is included at the end of the > new string formed by the concatenation of both *in destination*./ > > You'd need something like > SetLength(cTekst, enoughToHoldThemAll); > and maybe also > cTekst[oldLength] := #0; > before the very first strcat. > > Updated my code : cTekst:=StrAlloc(600); cTekst:=#13'Now is the winter of our discontent'#13; cTekst:=StrCat(cTekst,'Made glorious summer by this sun of York;'#13); ... cTekst is still a PChar. Same problem : on the pi the program crashes on the first StrCat with a 216 error. An extra error, now on my OpenSuse-box : I finally do StrDispose(cTekst); And then the application crashes with a 216 error. Leaving that StrDispose out it runs fine, but then there's a memory-leak. FWIW, I'm using FPC 2.6.5 (SVN version 49333M) on OpenSuse and 3.0.0 on the pi. Koenraad -- _______________________________________________ Lazarus mailing list http://lists.lazarus-ide.org/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20160624/c5a52f3b/attachment.html>

Reply by email

Sven Barth
to Koenraad Lelong: Op 23-06-16 om 21:38 schreef Martin Grajcar: Updated my code : cTekst:=StrAlloc(600);…
"Koenraad Lelong" wrote 6 lines
Updated my code : cTekst:=StrAlloc(600); cTekst:=#13'Now is the winter of our discontent'#13; cTekst:=StrCat(cTekst,'Made glorious summer by this sun of York;'#13);

You need to use StrCat for the assignment after the StrAlloc as well, otherwise you'd just get rid of the pointer to your allocated memory returning to your original situation.

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20160624/9b0587b5/attachment.html>

Reply by email

Koenraad Lelong
to Yann Mérignac: 1 cTekst:=StrAlloc(600); 2 cTekst:=#13'Now is the winter of our discontent'#13; 3…

Op 24-06-16 om 10:22 schreef Yann Mérignac:

Show quoted text 8 lines
var S : String; cTekst : PChar; begin S := #13'Now is the winter of our discontent'#13; S := S + 'Made glorious summer by this sun of York;'#13; cTekst := @S[1]; end;

Hi,

This works, both on OpenSuse and Raspberry Pi.

Thanks, although I still don't grasp how PChar should be used.

Koenraad.

Reply by email

David W Noon
to Koenraad Lelong

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Fri, 24 Jun 2016 20:37:52 +0200, Koenraad Lelong () wrote about "Re: [Lazarus] strcat problem"
(in ):

[snip]

Thanks, although I still don't grasp how PChar should be used.

The PChar type is a pointer to a NUL-terminated string. It uses C semantics and C-like syntax.

    program pchar_test;
    uses strings;
    var
       cTekst: PChar;
    begin
       cTekst := StrAlloc(200); { String buffer of 200 bytes. }
       { This is how we assign and concatenate strings in C. }
       StrCopy(cTekst, #13'Now is the winter of our discontent'#13);
       StrCat(cTekst, 'Made glorious summer by this sun of York'#13);
       StrCat(cTekst, 'And all the clouds that lour''d upon our ');
       StrCat(cTekst, 'house'#13);
       writeln(cTekst^); { De-reference the pointer. }
       StrDispose(cTekst); { Free the string buffer. }
    end.

After reading this, you should now know why C sucks as a string processing language, and why C++ implemented the std::string class to replace all this function call buffoonery.
- --
Regards,

Dave [RLU #314465]
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* (David W Noon)
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iEYEARECAAYFAldtincACgkQogYgcI4W/5TjPwCfQdXlunrHTf4DSCse9JcM8DyG 6VUAn1KpAtlDH2J4BR7HPxATKVsNTVHy
=+TJI
-----END PGP SIGNATURE-----

Reply by email

Koenraad Lelong
to David W Noon

Op 24-06-16 om 21:31 schreef David W Noon:

Show quoted text 7 lines
After reading this, you should now know why C sucks as a string processing language, and why C++ implemented the std::string class to replace all this function call buffoonery. - -- Regards, Dave [RLU #314465]

I think we're spoiled (fpc users), but not too much. The original c-code was this :
char *TEXT=
"\n\
Now is the winter of our discontent\n\
Made glorious summer by this sun of York;\n\
And all the clouds that lour'd upon our house\n\
In the deep bosom of the ocean buried.\n\
Now are our brows bound with victorious wreaths;\n\ Our bruised arms hung up for monuments;\n\
Our stern alarums changed to merry meetings,\n\
Our dreadful marches to delightful measures.\n\
Grim-visaged war hath smooth'd his wrinkled front;\n\ And now, instead of mounting barded steeds\n\
To fright the souls of fearful adversaries,\n\
He capers nimbly in a lady's chamber\n\
To the lascivious pleasing of a lute.\n\
";

I had to "improvise" and somehow put together that string which is really a constant here, or put that whole string on one line. Or does fpc have a similar construct to break strings in different lines like this c-code does ?

It's the first time I knowingly used a PChar and I want to learn more about it, because sooner or later I will need it again.

FWIW, with this problem "solved" I got a working port of pigpio, with a test/demo-application. If anyone is interested, please ask. It's the stuff that _uses_ the pigpio-daemon.

Koenraad.

Reply by email

David W Noon
to Koenraad Lelong

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Fri, 24 Jun 2016 22:46:45 +0200, Koenraad Lelong () wrote about "Re: [Lazarus] strcat problem"
(in ):

[snip]

Show quoted text 11 lines
I think we're spoiled (fpc users), but not too much. The original c-code was this : char *TEXT= "\n\ Now is the winter of our discontent\n\ Made glorious summer by this sun of York;\n\ And all the clouds that lour'd upon our house\n\ In the deep bosom of the ocean buried.\n\ Now are our brows bound with victorious wreaths;\n\ Our bruised arms hung up for monuments;\n\ Our stern alarums changed to merry meetings,\n\ Our dreadful marches to delightful measures.\n\ Grim-visaged war hath smooth'd his wrinkled front;\n\ And now, instead of mounting barded steeds\n\ To fright the souls of fearful adversaries,\n\ He capers nimbly in a lady's chamber\n\ To the lascivious pleasing of a lute.\n\ ";

That is some ugly code, even for C. I would have written it differently.

I had to "improvise" and somehow put together that string which is really a constant here, or put that whole string on one line. Or does fpc have a similar construct to break strings in different lines like this c-code does ?
  const
     TEXT : ansistring =
        #10'Now is the winter of our discontent'#10
        'Made glorious summer by this sun of York;'#10
        'And all the clouds that lour''d upon our house'#10
        'In the deep bosom of the ocean buried.'#10
        'Now are our brows bound with victorious wreaths;'#10
        'Our bruised arms hung up for monuments;'#10
        'Our stern alarums changed to merry meetings,'#10
        'Our dreadful marches to delightful measures.'#10
        'Grim-visaged war hath smooth''d his wrinkled front;'#10
        'And now, instead of mounting barded steeds'#10
        'To fright the souls of fearful adversaries,'#10
        'He capers nimbly in a lady''s chamber'#10
        'To the lascivious pleasing of a lute.'#10#0;

Note that '\n' is actually #10, not #13.

You can now use @TEXT as your PChar pointer value.
- --
Regards,

Dave [RLU #314465]
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* (David W Noon)
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iEYEARECAAYFAldtu0QACgkQogYgcI4W/5QgjACfb/WbAPNmHfs+X5CeP0nqjnzv ZNsAnibU3Kf+z6ih+r0DjDXCMTZOQnH6
=OQIa
-----END PGP SIGNATURE-----

Reply by email

David W Noon
to David W Noon

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Fri, 24 Jun 2016 23:59:16 +0100, David W Noon
() wrote about "Re: [Lazarus] strcat
problem" (in ):

You can now use @TEXT as your PChar pointer value.

Correction: I think that should be @TEXT[1] for the pointer.
- --
Regards,

Dave [RLU #314465]
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* (David W Noon)
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iEYEARECAAYFAldtvnEACgkQogYgcI4W/5SUZwCfS1pFnIwF+yDLiunuhNxCVCXj I7IAn1uGI0xW7ObLSPye1esB+3tUbcKr
=t9fr
-----END PGP SIGNATURE-----

Reply by email

Sven Barth
to David W Noon
"David W Noon" wrote 11 lines
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Fri, 24 Jun 2016 23:59:16 +0100, David W Noon () wrote about "Re: [Lazarus] strcat problem" (in ): > You can now use @TEXT as your PChar pointer value. Correction: I think that should be @TEXT[1] for the pointer.

Or use PChar(TEXT) and let the compiler deal with that problem ;)

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20160625/14c8459d/attachment.html>

Reply by email

Koenraad Lelong
to David W Noon: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Fri, 24 Jun 2016 22:46:45 +0200,…

Op 25-06-16 om 00:59 schreef David W Noon:

Show quoted text 5 lines
const TEXT : ansistring = #10'Now is the winter of our discontent'#10 'Made glorious summer by this sun of York;'#10

Fatal: Syntax error, ";" expected but "const string" found

'And all the clouds that lour''d upon our house'#10

...

Does not compile. Or do I need some compiler-switch ?

Koenraad

Reply by email

Howard Page-Clark
to Koenraad Lelong
Koenraad Lelong wrote 11 lines
Op 25-06-16 om 00:59 schreef David W Noon: > > const > TEXT : ansistring = > #10'Now is the winter of our discontent'#10 > 'Made glorious summer by this sun of York;'#10 Fatal: Syntax error, ";" expected but "const string" found > 'And all the clouds that lour''d upon our house'#10 ... Does not compile. Or do I need some compiler-switch ?

No, you need concatenation operators inserted:

const
TEXT : ansistring =
#10'Now is the winter of our discontent'#10
+'Made glorious summer by this sun of York;'#10
+'And all the clouds that lour''d upon our house'#10 +'In the deep bosom of the ocean buried.'#10
+ etc...

Reply by email

Unknown author
to Koenraad Lelong: I used strcat to make a long PChar. On my OpenSuse-box this works fine. On the…
Koenraad Lelong wrote 6 lines
Hi, I used strcat to make a long PChar. On my OpenSuse-box this works fine. On the RaspberryPi, is gives a runtime error 216. Any suggestions what could be the problem ?

FWIW: i know you probably have your solution already as i missed this when you first posted it... i came up with two solutions that seem to work ok... i'm not sure which i prefer, though...

edit: wow... now that i've read the thread(s), it is kinda funny how that saying about "only so many ways to do X" comes to play... FWIW: these two below? their compiled sizes are only about 100 bytes different...

program pchartest1;
uses
   strings;
var
   cTekst : pchar;
begin
   cTekst := strAlloc(600);
   strCat(cTekst, #10);
   strCat(cTekst, 'Now is the winter of our discontent'#10);
   strCat(cTekst, 'Made glorious summer by this sun of York;'#10);
   strCat(cTekst, 'And all the clouds that lour''d upon our house'#10);
   strCat(cTekst, 'In the deep bosom of the ocean buried.'#10);
   strCat(cTekst, 'Now are our brows bound with victorious wreaths;'#10);
   strCat(cTekst, 'Our bruised arms hung up for monuments;'#10);
   strCat(cTekst, 'Our stern alarums changed to merry meetings,'#10);
   strCat(cTekst, 'Our dreadful marches to delightful measures.'#10);
   strCat(cTekst, 'Grim-visaged war hath smooth''d his wrinkled front;'#10);
   strCat(cTekst, 'And now, instead of mounting barded steeds'#10);
   strCat(cTekst, 'To fright the souls of fearful adversaries,'#10);
   strCat(cTekst, 'He capers nimbly in a lady''s chamber'#10);
   strCat(cTekst, 'To the lascivious pleasing of a lute.'#10);
   writeln(cTekst);
   strDispose(cTekst);
end.
program pchartest2;

const
cTekst : ansistring =
#10
+'Now is the winter of our discontent'#10
+'Made glorious summer by this sun of York;'#10
+'And all the clouds that lour''d upon our house'#10 +'In the deep bosom of the ocean buried.'#10
+'Now are our brows bound with victorious wreaths;'#10 +'Our bruised arms hung up for monuments;'#10
+'Our stern alarums changed to merry meetings,'#10 +'Our dreadful marches to delightful measures.'#10 +'Grim-visaged war hath smooth''d his wrinkled front;'#10 +'And now, instead of mounting barded steeds'#10
+'To fright the souls of fearful adversaries,'#10
+'He capers nimbly in a lady''s chamber'#10

              +'To the lascivious pleasing of a lute.'#10#0;
begin
   writeln(pchar(cTekst));
end.
NOTE: No off-list assistance is given without prior approval. *Please keep mailing list traffic on the list* unless private contact is specifically requested and granted.

Reply by email

David W Noon
to Howard Page-Clark: No, you need concatenation operators inserted: const TEXT : ansistring = #10'Now is the…

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Sat, 25 Jun 2016 13:39:34 +0100, Howard Page-clark () wrote about "Re: [Lazarus] strcat problem" (in
):

[snip]

Show quoted text 6 lines
No, you need concatenation operators inserted: const TEXT : ansistring = #10'Now is the winter of our discontent'#10 +'Made glorious summer by this sun of York;'#10 +'And all the clouds that lour''d upon our house'#10 +'In the deep bosom of the ocean buried.'#10

Yes, that's the ticket!

I thought those #dd characters implicitly concatenated to any adjacent string, but it seems that spaces and/or line breaks can prevent that.
- --
Regards,

Dave [RLU #314465]
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* (David W Noon)
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iEYEARECAAYFAlduqVsACgkQogYgcI4W/5T1pQCeMasyRRriUkODdxVtCm2fm5Gq /5AAoNVcO3W6wHuRfcwpEVPVSxjTb+x7
=F0xp
-----END PGP SIGNATURE-----

Reply by email

Koenraad Lelong
to Howard Page-Clark: No, you need concatenation operators inserted: const TEXT : ansistring = #10'Now is the…

Op 25-06-16 om 14:39 schreef Howard Page-Clark:

Show quoted text 23 lines
On 25/06/16 12:38, Koenraad Lelong wrote: > Op 25-06-16 om 00:59 schreef David W Noon: >> >> const >> TEXT : ansistring = >> #10'Now is the winter of our discontent'#10 >> 'Made glorious summer by this sun of York;'#10 > Fatal: Syntax error, ";" expected but "const string" found >> 'And all the clouds that lour''d upon our house'#10 > ... > > Does not compile. Or do I need some compiler-switch ? No, you need concatenation operators inserted: const TEXT : ansistring = #10'Now is the winter of our discontent'#10 +'Made glorious summer by this sun of York;'#10 +'And all the clouds that lour''d upon our house'#10 +'In the deep bosom of the ocean buried.'#10 + etc...

Soo simple, why didn't I think of that.

I finally have this :
cTekst : PChar =
#10'Now is the winter of our discontent'#10
+'Made glorious summer by this sun of York;'#10
+'And all the clouds that lour''d upon our house'#10 +'In the deep bosom of the ocean buried.'#10
+'Now are our brows bound with victorious wreaths;'#10 +'Our bruised arms hung up for monuments;'#10
+'Our stern alarums changed to merry meetings,'#10 +'Our dreadful marches to delightful measures.'#10 +'Grim-visaged war hath smooth''d his wrinkled front;'#10 +'And now, instead of mounting barded steeds'#10
+'To fright the souls of fearful adversaries,'#10
+'He capers nimbly in a lady''s chamber'#10

         +'To the lascivious pleasing of a lute.'#10;

Works fine on OpenSuse and Raspberry Pi.

Thanks all.

Koenraad.

Reply by email