hi Ivan,
try the following piece of code:
var
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
Earlier message 25 lines
----- Original Message -----
From: Ivan Montes
To:
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
I'm
> 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 -
>
http://lists.freepascal.org/mailman/listinfo/fpc-pascal