Sign in Join

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

Mailing lists / fpc-pascal / 2001-10

ansistrings

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

Ivan Montes

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

Reply by email

Anton Tichawa
to Ivan Montes

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

Reply by email