[DUG] String Concatenation
Allan, Samuel
S.A.Allan at massey.ac.nz
Fri Nov 4 12:04:08 NZDT 2005
We have a weird problem where we are building a string up. It is quite a
large string, but not exceptionally large. About maybe 1000 characters.
The code to create the string approximates:
insertString, finalString: string;
for i := 0 to maxDataIndex do
insertString := insertString + dataItem[i];
finalString := CONSTANT_A + insertString + CONSTANT_B + insertString +
CONSTANT_C;
Without throwing an overflow warning or any other warning, this code
results in a finalString where the first instance of insertString is
whole and complete. The second instance is interrupted half-way by what
looks like a random memory dump, and there is no CONSTANT_C afterwards.
insertString remains pristine and untouched.
We have also tried several variations on the above code:
Using Copy() to create two additional strings, one for each insert. Same
result for finalString, both additional insert strings are fine.
Putting placeholder tokens in the finalString, then running
StringReplace(). Same result.
We tried to isolate the code in a separate application. The separate
application works fine, as you would expect. So we think it may be
something to do not with the code itself, but with the structure of our
application. However, code like this is widely used within this
application and elsewhere works fine.
Our application implicitly compiles several packages into itself. The
code in question is in one of these packages. So compiling any change to
it requires compiling the package, then compiling the application.
We have searched the web, and found an exact match for this posted in
some newsgroup in 1998, but there were no responses. The match does not
mention packages however.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://ns3.123.co.nz/pipermail/delphi/attachments/20051104/feeeb59c/attachment.html
More information about the Delphi
mailing list