Anton Tichawa anton.tichawa at chello.at
Fri Oct 26 02:59:41 CEST 2001

hi Ivan,

try the following piece of code:

  S: String;
  S := '';  // make S empty
  S[Length(S)] := 'a';

This results in an access violation, because, AFAIK, an empty ansi-string
actually has no space allocated, but is a nil pointer. Make sure that your
strings aren't empty before changing the last character (if the string is
empty, there is no last character). Hope this helps.

Anton Tichawa

----- Original Message -----
From: Ivan Montes <Drslump at btopenworld.com>
To: <fpc-pascal at deadlock.et.tudelft.nl>
Sent: Friday, October 26, 2001 2:46 AM
Subject: [fpc-pascal]ansistrings

> Hi everybody,
> I just discover ansi-strings (long strings) a couple of months ago, and
> very happy with them. They help me a lot in everything I do.
> But I found that if I access the last character of it, like
> s[length(s)]:='A'; sometimes I get an access violation. Why is that?
> If it's because I can't do that due to the internals of ansistrings, how
> should I do to change the last character of the string?
> thanks, Ivan
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal

More information about the fpc-pascal mailing list