On Sun, 17 Mar 2002, Prof Abimbola Olowofoyeku wrote:
On 17 Mar 2002 at 13:16, Martin Liddle wrote:
[..]
However I am now stuck because of the following problem:
Program WriteTest;
Procedure ZWriteln(AString:String); Begin AString:=AString+'ML'; Writeln('String [',AString,'] Length is ',Length(AString)); End;
Begin ZWriteln(' '); End.
What I see is that length is reported as 1 i.e. the string concatenation is failing. Is this expected behaviour or a bug?
It is a bug alright. If you pass a string variable rather than a literal to 'ZWriteln', the concatentation is successful. So, something seems to have gone awry somewhere.
As a work around you might try this:
Program WriteTest;
Procedure ZWriteln(AString:String); var BString : string( length(AString)+20 ); {used 20 instead of 2 to show that the length reported didn't come from here} Begin BString:=AString+'ML'; Writeln('String [',BString,'] Length is ',Length(BString)); End;
Begin ZWriteln(' '); End.
I also note that trying to set the Capacity of a string schema is now flagged as an error.
My understanding that it should always have been flagged as an error.
Is there an "official" way to set the capacity? We were only setting the capacity as a workaround for problems in previous versions of gpc where under various circumstances it wasn't initialised properly. My first stab is to comment out all the places where we were setting capacity but I can't test if everything is OK because of the problem noted above.
'SetLength' should work. However, I am not sure that you can use it for increasing (as opposed to decreasing) the maximum length of a string.
Be carefull not to confuse length with capacity.
Also, length =< capacity and you can get garbage if you increase the length into an uninitialized area of the string's capacity.
Russ