<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="IncrediMail 1.0" name=GENERATOR></HEAD>
<BODY style="BACKGROUND-POSITION: 0px 0px; FONT-SIZE: 12pt; MARGIN: 5px 10px 10px; FONT-FAMILY: Arial" bgColor=#ffffff background="" scroll=yes ORGYPOS="0">
<TABLE id=INCREDIMAINTABLE cellSpacing=0 cellPadding=2 width="100%" border=0>
<TBODY>
<TR>
<TD id=INCREDITEXTREGION style="FONT-SIZE: 12pt; CURSOR: auto; FONT-FAMILY: Arial" width="100%">
<DIV>
<DIV>&gt;&gt;Note you really wanted maxDataIndex-1</DIV>
<DIV>interesting assumption on psuedo code :)</DIV>
<DIV>&nbsp;</DIV>
<DIV>had it been called Count I would agree. but maxDataIndex sounds like an index to me.</DIV>
<DIV>&nbsp;</DIV>
<DIV>ie </DIV>
<DIV>count = 6</DIV>
<DIV>MaxDataIndex=5</DIV>
<DIV>start=0</DIV>
<DIV>&nbsp;</DIV>
<DIV>of course, an assumption on my part too. It could also be that count is 50000, but they only wanted maxDataIndex of 3... and on and on.. so the -1 bit is quite irrelevant. </DIV>
<DIV>&nbsp;</DIV>
<DIV>You should turn on range checking and overflow checking though, and use fastmem, memcheck or memproof to test your application</DIV>
<DIV>&nbsp;</DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV id=IncrediOriginalMessage><I>-------Original Message-------</I></DIV>
<DIV>&nbsp;</DIV>
<DIV id=receivestrings>
<DIV dir=ltr style="FONT-SIZE: 11pt"><I><B>From:</B></I> <A href="mailto:r.gupta@xtra.co.nz">Rohit Gupta</A></DIV>
<DIV dir=ltr style="FONT-SIZE: 11pt"><I><B>Date:</B></I> 11/04/05 12:49:05</DIV>
<DIV dir=ltr style="FONT-SIZE: 11pt"><I><B>To:</B></I> <A href="mailto:delphi@ns3.123.co.nz">NZ Borland Developers Group - Delphi List</A></DIV>
<DIV dir=ltr style="FONT-SIZE: 11pt"><I><B>Subject:</B></I> Re: [DUG] String Concatenation</DIV></DIV>
<DIV>&nbsp;</DIV>
<DIV>You havent mentioned what version you are using.&nbsp;&nbsp;D5 has a severe</DIV>
<DIV>problem where it gets confused between shortstring and ansistring.&nbsp;&nbsp;It</DIV>
<DIV>just shows up at random, when you examine the assembler code, you can</DIV>
<DIV>see the fault.&nbsp;&nbsp;The only solution I found was to explicitly declare</DIV>
<DIV>ansistring and shortstring instead of using string.&nbsp;&nbsp;Of course thsi</DIV>
<DIV>still stuffs up because all vcl uses string.</DIV>
<DIV>&nbsp;</DIV>
<DIV>I havent had any problems with D7 or D2005.</DIV>
<DIV>&nbsp;</DIV>
<DIV>You dont have any timers or events stuffing things up ?</DIV>
<DIV>&nbsp;</DIV>
<DIV>Note you really wanted maxDataIndex-1</DIV>
<DIV>&nbsp;</DIV>
<DIV>Allan, Samuel wrote:</DIV>
<DIV>&nbsp;</DIV>
<DIV>&gt; We have a weird problem where we are building a string up. It is quite</DIV>
<DIV>&gt; a large string, but not exceptionally large. About maybe 1000</DIV>
<DIV>&gt; characters. The code to create the string approximates:</DIV>
<DIV>&gt;</DIV>
<DIV>&gt; insertString, finalString: string;</DIV>
<DIV>&gt;</DIV>
<DIV>&gt; for i := 0 to maxDataIndex do</DIV>
<DIV>&gt;&nbsp;&nbsp;&nbsp;&nbsp;insertString := insertString + dataItem[i];</DIV>
<DIV>&gt;</DIV>
<DIV>&gt; finalString := CONSTANT_A + insertString + CONSTANT_B + insertString +</DIV>
<DIV>&gt; CONSTANT_C;</DIV>
<DIV>&gt;</DIV>
<DIV>&gt; Without throwing an overflow warning or any other warning, this code</DIV>
<DIV>&gt; results in a finalString where the first instance of insertString is</DIV>
<DIV>&gt; whole and complete. The second instance is interrupted half-way by</DIV>
<DIV>&gt; what looks like a random memory dump, and there is no CONSTANT_C</DIV>
<DIV>&gt; afterwards. insertString remains pristine and untouched.</DIV>
<DIV>&gt;</DIV>
<DIV>&gt; We have also tried several variations on the above code:</DIV>
<DIV>&gt;</DIV>
<DIV>&gt; Using Copy() to create two additional strings, one for each insert.</DIV>
<DIV>&gt; Same result for finalString, both additional insert strings are fine.</DIV>
<DIV>&gt;</DIV>
<DIV>&gt; Putting placeholder tokens in the finalString, then running</DIV>
<DIV>&gt; StringReplace(). Same result.</DIV>
<DIV>&gt;</DIV>
<DIV>&gt; We tried to isolate the code in a separate application. The separate</DIV>
<DIV>&gt; application works fine, as you would expect. So we think it may be</DIV>
<DIV>&gt; something to do not with the code itself, but with the structure of</DIV>
<DIV>&gt; our application. However, code like this is widely used within this</DIV>
<DIV>&gt; application and elsewhere works fine.</DIV>
<DIV>&gt;</DIV>
<DIV>&gt; Our application implicitly compiles several packages into itself. The</DIV>
<DIV>&gt; code in question is in one of these packages. So compiling any change</DIV>
<DIV>&gt; to it requires compiling the package, then compiling the application.</DIV>
<DIV>&gt;</DIV>
<DIV>&gt; We have searched the web, and found an exact match for this posted in</DIV>
<DIV>&gt; some newsgroup in 1998, but there were no responses. The match does</DIV>
<DIV>&gt; not mention packages however.</DIV>
<DIV>&gt;</DIV>
<DIV>&gt;</DIV>
<DIV>&gt;------------------------------------------------------------------------</DIV>
<DIV>&gt;</DIV>
<DIV>&gt;_______________________________________________</DIV>
<DIV>&gt;Delphi mailing list</DIV>
<DIV>&amp;<A href="mailto:gt;Delphi@ns3.123.co.nz">gt;Delphi@ns3.123.co.nz</A></DIV>
<DIV>&gt;<A href="http://ns3.123.co.nz/mailman/listinfo/delphi">http://ns3.123.co.nz/mailman/listinfo/delphi</A></DIV>
<DIV>&gt;</DIV>
<DIV>&gt;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>_______________________________________________</DIV>
<DIV>Delphi mailing list</DIV>
<DIV><A href="mailto:Delphi@ns3.123.co.nz">Delphi@ns3.123.co.nz</A></DIV>
<DIV><A href="http://ns3.123.co.nz/mailman/listinfo/delphi">http://ns3.123.co.nz/mailman/listinfo/delphi</A></DIV></TD></TR>
<TR>
<TD id=INCREDIFOOTER width="100%">
<TABLE cellSpacing=0 cellPadding=0 width="100%">
<TBODY>
<TR>
<TD width="100%"></TD>
<TD id=INCREDISOUND vAlign=bottom align=middle></TD>
<TD id=INCREDIANIM vAlign=bottom align=middle></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><SPAN id=IncrediStamp><SPAN ltr??><A href="http://www.incredimail.com/index.asp?id=409&amp;lang=9"><IMG alt="" hspace=0 src="cid:2E02F6FF-1F08-4733-9477-DFA996A6CC50" align=baseline border=0></A></SPAN></SPAN></BODY></HTML>