<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[EAccessViolationException help]]></title><description><![CDATA[<p>I have code running that constantly throws an Access Violation on Windows XP. This exception only occurs however after around 10 to 20 thousand times running this function. I can catch the exception but want to get rid of it completely, however cannot figure out where it is coming from. Code is below (str is a simple string parser). Any help is greatly appreciated.</p>
<pre><code class="language-cpp">//--------------------------------------------------------

        unsigned char *inbuffer;
        AnsiString tmp;
        struct timeval current;
        inbuffer = new unsigned char[Count+2];
        myComPort-&gt;Read(inbuffer, Count);
        str.reset();
        try {
        if(Form2-&gt;mode == TForm2::HEX_MODE &amp;&amp; !Form2-&gt;BufferDisabled-&gt;Checked){
                for(int i=0; i&lt;Count; i++){
                        tmp.sprintf(&quot;%0x &quot;, inbuffer[i]);
                        if(tmp.Length() &lt; 3)
                                tmp = AnsiString(&quot;0&quot;) + tmp;
                        str &lt;&lt; tmp.c_str() &lt;&lt; &quot; &quot;;
                }
                if(Form2-&gt;ReceiveBuffer.Length() + str.length() &lt; Form2-&gt;MaxBufLen){
                        Form2-&gt;ReceiveBuffer += AnsiString(str.c_str()).UpperCase();
                }
                else{
                        unsigned int n=0;
                        for(int count=0;n&lt;=str.length();count++)
                                n += (*(Form2-&gt;Memo-&gt;Lines))[count].Length();
                        Form2-&gt;ReceiveBuffer.Delete(0, n);
                        Form2-&gt;ReceiveBuffer += AnsiString(str.c_str()).UpperCase();
                }
        }
        else if(Form2-&gt;mode == TForm2::ASCII_MODE &amp;&amp; !Form2-&gt;BufferDisabled-&gt;Checked){
                inbuffer[Count] = '\0';
                if(Form2-&gt;ReceiveBuffer.Length() + strlen((char*)inbuffer) &gt; Form2-&gt;MaxBufLen){
                        Form2-&gt;ReceiveBuffer.Delete(0, strlen((char*)inbuffer));
                }
                Form2-&gt;ReceiveBuffer += AnsiString((char*)inbuffer);
                if(Form2-&gt;logdata){
                        std::ofstream outfile;
                        outfile.open(Form2-&gt;LogFileName.c_str(), std::ofstream::out | std::ofstream::app);
                        outfile &lt;&lt; (char*)inbuffer;
                        outfile.close();
                }
        }
        }
        catch (const EAccessViolation &amp; vae)
        {
                ShowMessage(&quot;Misread message&quot;);
        }
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/150747/eaccessviolationexception-help</link><generator>RSS for Node</generator><lastBuildDate>Sat, 08 Aug 2026 15:56:49 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/150747.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 19 Jun 2006 21:18:40 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to EAccessViolationException help on Mon, 19 Jun 2006 22:17:40 GMT]]></title><description><![CDATA[<p>I have code running that constantly throws an Access Violation on Windows XP. This exception only occurs however after around 10 to 20 thousand times running this function. I can catch the exception but want to get rid of it completely, however cannot figure out where it is coming from. Code is below (str is a simple string parser). Any help is greatly appreciated.</p>
<pre><code class="language-cpp">//--------------------------------------------------------

        unsigned char *inbuffer;
        AnsiString tmp;
        struct timeval current;
        inbuffer = new unsigned char[Count+2];
        myComPort-&gt;Read(inbuffer, Count);
        str.reset();
        try {
        if(Form2-&gt;mode == TForm2::HEX_MODE &amp;&amp; !Form2-&gt;BufferDisabled-&gt;Checked){
                for(int i=0; i&lt;Count; i++){
                        tmp.sprintf(&quot;%0x &quot;, inbuffer[i]);
                        if(tmp.Length() &lt; 3)
                                tmp = AnsiString(&quot;0&quot;) + tmp;
                        str &lt;&lt; tmp.c_str() &lt;&lt; &quot; &quot;;
                }
                if(Form2-&gt;ReceiveBuffer.Length() + str.length() &lt; Form2-&gt;MaxBufLen){
                        Form2-&gt;ReceiveBuffer += AnsiString(str.c_str()).UpperCase();
                }
                else{
                        unsigned int n=0;
                        for(int count=0;n&lt;=str.length();count++)
                                n += (*(Form2-&gt;Memo-&gt;Lines))[count].Length();
                        Form2-&gt;ReceiveBuffer.Delete(0, n);
                        Form2-&gt;ReceiveBuffer += AnsiString(str.c_str()).UpperCase();
                }
        }
        else if(Form2-&gt;mode == TForm2::ASCII_MODE &amp;&amp; !Form2-&gt;BufferDisabled-&gt;Checked){
                inbuffer[Count] = '\0';
                if(Form2-&gt;ReceiveBuffer.Length() + strlen((char*)inbuffer) &gt; Form2-&gt;MaxBufLen){
                        Form2-&gt;ReceiveBuffer.Delete(0, strlen((char*)inbuffer));
                }
                Form2-&gt;ReceiveBuffer += AnsiString((char*)inbuffer);
                if(Form2-&gt;logdata){
                        std::ofstream outfile;
                        outfile.open(Form2-&gt;LogFileName.c_str(), std::ofstream::out | std::ofstream::app);
                        outfile &lt;&lt; (char*)inbuffer;
                        outfile.close();
                }
        }
        }
        catch (const EAccessViolation &amp; vae)
        {
                ShowMessage(&quot;Misread message&quot;);
        }
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1081007</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1081007</guid><dc:creator><![CDATA[StrikeTheCore]]></dc:creator><pubDate>Mon, 19 Jun 2006 22:17:40 GMT</pubDate></item><item><title><![CDATA[Reply to EAccessViolationException help on Mon, 19 Jun 2006 22:19:44 GMT]]></title><description><![CDATA[<p>In welcher Zeile genau wird die AV ausgelöst?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1081021</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1081021</guid><dc:creator><![CDATA[Jansen]]></dc:creator><pubDate>Mon, 19 Jun 2006 22:19:44 GMT</pubDate></item><item><title><![CDATA[Reply to EAccessViolationException help on Tue, 20 Jun 2006 13:20:14 GMT]]></title><description><![CDATA[<p>Ich stellte es heraus dar. Das Problem war mit der Delete und dem beginnenden Index, die mit 0 beginnen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1081449</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1081449</guid><dc:creator><![CDATA[StrikeTheCore]]></dc:creator><pubDate>Tue, 20 Jun 2006 13:20:14 GMT</pubDate></item></channel></rss>