The African Chief wrote:
Problem: Under BP, one can do; Var S:String; Count:Integer; .... Dec(S[0], Count);
This does not compile under GPC, but "Dec(Length(S), Count)" compiles, and seems to work okay.
Then I think this is a bug in GPC, and must be prevented. The Length field of a string should only be accessible read-only.
However, there is (in the current developer version, not yet in the last beta) a built-in function AssignLength which is the proper way to directly wirte to the length field of a string (if messing with the length can be called proper at all... ;-)
Observation: This is an incompatbility b/w BP and GPC - probably because of the way strings are implemented under GPC.
Right.
Questions:
- Is GPC ever going to support the BP syntax "Dec(S[0], Count);"
?
Short answer, yes, sometime. More details can be found in some other discussions in the list.
- Is it desirable to do so ?
Yes. Mainly for the reason you described.
(obviously this would entail changes to the internal GPC string format ???)
Not changes to the "real" Pascal strings; rather, it would mean introducing a new string type with automatic conversions as far as possible.
Frank Heckenbach wrote:
The African Chief wrote:
Problem: Under BP, one can do; Var S:String; Count:Integer; .... Dec(S[0], Count);
This does not compile under GPC, but "Dec(Length(S), Count)" compiles, and seems to work okay.
Then I think this is a bug in GPC,
Yes, I thought it odd that I could do that (but I was glad!).
and must be prevented. The Length field of a string should only be accessible read-only.
I can think of many uses for this facility.
However, there is (in the current developer version, not yet in the last beta) a built-in function AssignLength which is the proper way to directly wirte to the length field of a string (if messing with the length can be called proper at all... ;-)
Like I said, there are many uses for that facility - and BP programmers have been doing it for a long time (with s[0]).
BTW: the new function you refer to (AssignLength) exists in 32-bit Delphi as "SetLength" - any chance of renaming your function to "SetLength"? (for compatibility with Delphi). The Delphi procedure is defined as; "procedure SetLength(var S: string; NewLength: Integer);" It works both for long strings and short strings.
I suppose we could always implement "SetLength" as a shell for "AssignLength", but is there any harm in changing the name at this point in time?
Best regards, The Chief -------- Dr. Abimbola A. Olowofoyeku (The African Chief) Email: laa12@keele.ac.uk Homepage: http://ourworld.compuserve.com/homepages/African_Chief/ Author of: Chief's Installer Pro 4.01 for Win16 and Win32: http://www.simtel.net/pub/simtelnet/win3/install/chief401.zip