<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>>>Note you really wanted maxDataIndex-1</DIV>
<DIV>interesting assumption on psuedo code :)</DIV>
<DIV> </DIV>
<DIV>had it been called Count I would agree. but maxDataIndex sounds like an index to me.</DIV>
<DIV> </DIV>
<DIV>ie </DIV>
<DIV>count = 6</DIV>
<DIV>MaxDataIndex=5</DIV>
<DIV>start=0</DIV>
<DIV> </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> </DIV>
<DIV>You should turn on range checking and overflow checking though, and use fastmem, memcheck or memproof to test your application</DIV>
<DIV> </DIV> </DIV>
<DIV> </DIV>
<DIV id=IncrediOriginalMessage><I>-------Original Message-------</I></DIV>
<DIV> </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> </DIV>
<DIV>You havent mentioned what version you are using. D5 has a severe</DIV>
<DIV>problem where it gets confused between shortstring and ansistring. It</DIV>
<DIV>just shows up at random, when you examine the assembler code, you can</DIV>
<DIV>see the fault. The only solution I found was to explicitly declare</DIV>
<DIV>ansistring and shortstring instead of using string. Of course thsi</DIV>
<DIV>still stuffs up because all vcl uses string.</DIV>
<DIV> </DIV>
<DIV>I havent had any problems with D7 or D2005.</DIV>
<DIV> </DIV>
<DIV>You dont have any timers or events stuffing things up ?</DIV>
<DIV> </DIV>
<DIV>Note you really wanted maxDataIndex-1</DIV>
<DIV> </DIV>
<DIV>Allan, Samuel wrote:</DIV>
<DIV> </DIV>
<DIV>> We have a weird problem where we are building a string up. It is quite</DIV>
<DIV>> a large string, but not exceptionally large. About maybe 1000</DIV>
<DIV>> characters. The code to create the string approximates:</DIV>
<DIV>></DIV>
<DIV>> insertString, finalString: string;</DIV>
<DIV>></DIV>
<DIV>> for i := 0 to maxDataIndex do</DIV>
<DIV>> insertString := insertString + dataItem[i];</DIV>
<DIV>></DIV>
<DIV>> finalString := CONSTANT_A + insertString + CONSTANT_B + insertString +</DIV>
<DIV>> CONSTANT_C;</DIV>
<DIV>></DIV>
<DIV>> Without throwing an overflow warning or any other warning, this code</DIV>
<DIV>> results in a finalString where the first instance of insertString is</DIV>
<DIV>> whole and complete. The second instance is interrupted half-way by</DIV>
<DIV>> what looks like a random memory dump, and there is no CONSTANT_C</DIV>
<DIV>> afterwards. insertString remains pristine and untouched.</DIV>
<DIV>></DIV>
<DIV>> We have also tried several variations on the above code:</DIV>
<DIV>></DIV>
<DIV>> Using Copy() to create two additional strings, one for each insert.</DIV>
<DIV>> Same result for finalString, both additional insert strings are fine.</DIV>
<DIV>></DIV>
<DIV>> Putting placeholder tokens in the finalString, then running</DIV>
<DIV>> StringReplace(). Same result.</DIV>
<DIV>></DIV>
<DIV>> We tried to isolate the code in a separate application. The separate</DIV>
<DIV>> application works fine, as you would expect. So we think it may be</DIV>
<DIV>> something to do not with the code itself, but with the structure of</DIV>
<DIV>> our application. However, code like this is widely used within this</DIV>
<DIV>> application and elsewhere works fine.</DIV>
<DIV>></DIV>
<DIV>> Our application implicitly compiles several packages into itself. The</DIV>
<DIV>> code in question is in one of these packages. So compiling any change</DIV>
<DIV>> to it requires compiling the package, then compiling the application.</DIV>
<DIV>></DIV>
<DIV>> We have searched the web, and found an exact match for this posted in</DIV>
<DIV>> some newsgroup in 1998, but there were no responses. The match does</DIV>
<DIV>> not mention packages however.</DIV>
<DIV>></DIV>
<DIV>></DIV>
<DIV>>------------------------------------------------------------------------</DIV>
<DIV>></DIV>
<DIV>>_______________________________________________</DIV>
<DIV>>Delphi mailing list</DIV>
<DIV>&<A href="mailto:gt;Delphi@ns3.123.co.nz">gt;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>
<DIV>></DIV>
<DIV>></DIV>
<DIV> </DIV>
<DIV> </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&lang=9"><IMG alt="" hspace=0 src="cid:2E02F6FF-1F08-4733-9477-DFA996A6CC50" align=baseline border=0></A></SPAN></SPAN></BODY></HTML>