1. var s:string; ... s[1]:='#'; --> causes an access violation 2. Why is it no more…
Show quoted text 13 lines
It seems more to me that you're using objfpc or delphi mode so you get ansistrings?

Mailing lists / fpc-pascal / 2007-06
11 messages · 4 people ·
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
1. var s:string; ... s[1]:='#'; --> causes an access violation 2. Why is it no more…
It seems more to me that you're using objfpc or delphi mode so you get ansistrings?
Hello,
1.
var s:string;
...
s[1]:='#'; --> causes an access violation2.
Why is it no more possible to assign the length index s[0] in a string? I find that is too much security to supress that.
It is cutting responsibility from the programmers.
Kind regards,
Rainer
You are using ansistrings instead of shortstrings. Use SetLength() first to allocate memory.
Peter
Does that mean that var s:string; is definig an ansistring in delphi mode? In the…
Unlikely. string meant for years ansistring in objfpc/delphi mode.
is it now changing generally to ansistrings? How can I assign "normal" pascalstrings?
shortstring
You are using ansistrings instead of shortstrings. Use SetLength() first to allocate…
Does that mean that
var s:string; is definig an ansistring in delphi mode?
In the previous version this works, is it now changing generally to ansistrings?
How can I assign "normal" pascalstrings?
Is there a description about the behaviour of strings and ansistrings in the various modes?
Kind regards,
Rainer
what does var s:string[12]; in delphimode mean? ansistring or shortstring? if ansistring,…
string[12] ?
Does that mean that var s:string; is definig an ansistring in delphi mode? In the…
Yes.
In the previous version this works, is it now changing generally to ansistrings?
Yes.
In old versions {$mode delphi} did not automatically imply {$h+}. Now it does.
How can I assign "normal" pascalstrings?
Put
{$h-}at the start of your file, or use the -Sh- option on the command-line.
Alternatively, define your string as
Var
S : Shortstring;This works in any mode, and is delphi compatible.
Is there a description about the behaviour of strings and ansistrings in the various modes?
Yes, the reference documentation. The only effect of the {$h} directive is to map String->Ansistring when {$h ON} or String-> Shortstring when {$h off} is in effect. You can always force either of those by explicitly using ansistring, shortstring or declaring a fixed-length string.
This is 100% delphi compatible. The only thing that has changed is that {$mode delphi} now implicitly implies {$h+}. This is again compatible with newer versions of Delphi, where {$H+} is now the default.
Hope this clarifies matters a bit. I'll add a statement of the changed behaviour to the documentation of {$mode} and {$H}
Michael.
what does var s:string[12]; in delphimode mean? ansistring or shortstring? if ansistring,…
Obviously, since the definition of shortstring is:
ShortString = String[255];So actually your above statement is equivalent to writing
Var s:string[255][12];which, you'll agree, is wrong :-)
Michael.
Unlikely. string meant for years ansistring in objfpc/delphi mode. shortstring
Florian Klaempfl wrote> How can I assign "normal" pascalstrings? shortstring
what does
var s:string[12];in delphimode mean?
ansistring or shortstring?
if ansistring, how can I get access to a "normal" pascal (short)string with maximum length of 12?
var s:shortstring[12];does not work in delphi mode.
Rainer
string[12] ?
ok, now I understand.
string means ansistring in delphi mode
and string[12] means shortstring with maximum length of 12 in delphi mode.
Thanks,
Kind regards
Rainer
Obviously, since the definition of shortstring is: ShortString = String[255]; So actually…
OK, this part I understand, now, thanks for explanation. I'm not deep involved in compiler programming, but it is good to know that string[255] also works.
Now, I use the www.frameworkpascal.com for a DOS Program and ported it to Linux, so that the program can run with DOS and Linux. Let it run in DOS with fpc compiler seems more work, so I run the program in DOS with the frameworkcompiler.
I did it now with additional compiler args -Sh- and it works, thanks.
Kind regards,
Rainer