<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    Hi Ross,<br>
    <br>
    That's interesting, because I would have thought that using
    StrCopy(Title, '12345') in this situation would have resulted in the
    same problem - the compiler must allocate the string differently in
    this case ;-)<br>
    <br>
    Regards,<br>
    <br>
    Bevan<br>
    <br>
    <br>
    <div class="moz-cite-prefix">On 13/05/2013 2:31 a.m., Ross Levis
      wrote:<br>
    </div>
    <blockquote cite="mid:009701ce4f1d$61a1c280$24e54780$@com"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html;
        charset=ISO-8859-1">
      <meta name="Generator" content="Microsoft Word 12 (filtered
        medium)">
      <style><!--
/* Font Definitions */
@font-face
        {font-family:PMingLiU;
        panose-1:2 2 3 0 0 0 0 0 0 0;}
@font-face
        {font-family:PMingLiU;
        panose-1:2 2 3 0 0 0 0 0 0 0;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:"\@PMingLiU";
        panose-1:2 2 3 0 0 0 0 0 0 0;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";
        color:black;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";
        color:black;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
        {mso-style-priority:99;
        mso-style-link:"Balloon Text Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:8.0pt;
        font-family:"Tahoma","sans-serif";
        color:black;}
span.BalloonTextChar
        {mso-style-name:"Balloon Text Char";
        mso-style-priority:99;
        mso-style-link:"Balloon Text";
        font-family:"Tahoma","sans-serif";}
span.apple-style-span
        {mso-style-name:apple-style-span;}
span.EmailStyle20
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:Consolas;
        color:black;}
span.EmailStyle23
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
      <div class="WordSection1">
        <p class="MsoNormal"><span
style="font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">In
            the end I did this&#8230;<o:p></o:p></span></p>
        <p class="MsoNormal"><span
style="font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
        <p class="MsoNormal"><span
style="font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">var
            TitleStr: string=&#8217;The DLL Title&#8217;;<o:p></o:p></span></p>
        <p class="MsoNormal"><span
style="font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">var
            Title: pChar;<o:p></o:p></span></p>
        <p class="MsoNormal"><span
style="font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">Title
            := @TitleStr[1];<o:p></o:p></span></p>
        <p class="MsoNormal"><span
style="font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
        <p class="MsoNormal"><span
style="font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">I
            could then use CopyStr elsewhere.<o:p></o:p></span></p>
        <p class="MsoNormal"><span
style="font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
        <p class="MsoNormal"><span
style="font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">Cheers.<o:p></o:p></span></p>
        <p class="MsoNormal"><span
style="font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
        <div>
          <div style="border:none;border-top:solid #B5C4DF
            1.0pt;padding:3.0pt 0cm 0cm 0cm">
            <p class="MsoNormal"><b><span
style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;;color:windowtext"
                  lang="EN-US">From:</span></b><span
style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;;color:windowtext"
                lang="EN-US"> <a class="moz-txt-link-abbreviated" href="mailto:delphi-bounces@listserver.123.net.nz">delphi-bounces@listserver.123.net.nz</a>
                [<a class="moz-txt-link-freetext" href="mailto:delphi-bounces@listserver.123.net.nz">mailto:delphi-bounces@listserver.123.net.nz</a>] <b>On
                  Behalf Of </b>Bevan Edwards<br>
                <b>Sent:</b> Sunday, 12 May 2013 7:52 PM<br>
                <b>To:</b> NZ Borland Developers Group - Delphi List<br>
                <b>Subject:</b> Re: [DUG] StrCopy problem<o:p></o:p></span></p>
          </div>
        </div>
        <p class="MsoNormal"><o:p>&nbsp;</o:p></p>
        <p class="MsoNormal" style="margin-bottom:12.0pt">Hi Ross,<br>
          <br>
          You don't say which version of Delphi you're using, but I
          assume it's pre-Unicode support, since you use PChar instead
          of PAnsiChar or PWideChar.<br>
          <br>
          Out of curiosity I built a small test application and traced
          through the source code for this snippet of code using the CPU
          window.&nbsp; What I noticed is that the address of the two strings
          assigned to 'a' and 'b' are part of program memory.&nbsp; More
          specifically, Delphi appears to store these strings
          immediately after the "return" opcode for the procedure and
          simply puts those addresses into 'a' and 'b'.&nbsp; Since this area
          of memory is protected while the application is running,
          that's why you get the error.<br>
          <br>
          By using:<br>
          a:=AllocMem(10);<br>
          StrCopy(a, 'abcdefghi');<br>
          b:='jklmnopqr';<br>
          StrCopy(a, b);<br>
          <br>
          The variable 'b' now points to application memory while 'a' is
          allocated a "write-enabled" memory address, so the access
          violation doesn't occur.<br>
          <br>
          Regards,<br>
          <br>
          Bevan<br>
          <br>
          <br>
          <o:p></o:p></p>
        <div>
          <p class="MsoNormal">On 12/05/2013 5:30 p.m., Ross Levis
            wrote:<o:p></o:p></p>
        </div>
        <blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
          <p class="MsoNormal"><span
style="font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">I
              did see a &amp; b had a pointer address allocated.&nbsp; It
              looked like a normal pointer address range.&nbsp; I&#8217;ll try
              allocating 10 bytes to a later and see what happens.</span><o:p></o:p></p>
          <p class="MsoNormal"><span
style="font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">&nbsp;</span><o:p></o:p></p>
          <p class="MsoNormal"><span
style="font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">Ross.</span><o:p></o:p></p>
          <p class="MsoNormal"><span
style="font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">&nbsp;</span><o:p></o:p></p>
          <div>
            <div style="border:none;border-top:solid #B5C4DF
              1.0pt;padding:3.0pt 0cm 0cm 0cm">
              <p class="MsoNormal"><b><span
style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"
                    lang="EN-US">From:</span></b><span
style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"
                  lang="EN-US"> <a moz-do-not-send="true"
                    href="mailto:delphi-bounces@listserver.123.net.nz">delphi-bounces@listserver.123.net.nz</a>
                  [<a moz-do-not-send="true"
                    href="mailto:delphi-bounces@listserver.123.net.nz">mailto:delphi-bounces@listserver.123.net.nz</a>]
                  <b>On Behalf Of </b>Bevan Edwards<br>
                  <b>Sent:</b> Sunday, 12 May 2013 4:48 PM<br>
                  <b>To:</b> <a moz-do-not-send="true"
                    href="mailto:delphi@listserver.123.net.nz">delphi@listserver.123.net.nz</a><br>
                  <b>Subject:</b> Re: [DUG] StrCopy problem</span><o:p></o:p></p>
            </div>
          </div>
          <p class="MsoNormal">&nbsp;<o:p></o:p></p>
          <div>
            <div>
              <p class="MsoNormal">Actually, based on that article
                a:='abcdefghi' should assign 10 bytes and include the
                zero byte at the end. But I wonder if the problem is due
                to where this data is stored and trying to copy b to a
                results in an attempt to write to protected memory?<o:p></o:p></p>
            </div>
            <div>
              <p class="MsoNormal">&nbsp;<o:p></o:p></p>
            </div>
            <div>
              <p class="MsoNormal">Have you tried allocating 10 bytes of
                memory to 'a' and then using StrCopy?<o:p></o:p></p>
            </div>
            <div>
              <p class="MsoNormal">&nbsp;<o:p></o:p></p>
            </div>
            <div>
              <p class="MsoNormal">Have you run the debugger and checked
                where the PChars 'a' and 'b' are pointing to before
                StrCopy?<o:p></o:p></p>
            </div>
            <div>
              <p class="MsoNormal">&nbsp;<o:p></o:p></p>
            </div>
          </div>
          <p class="MsoNormal" style="margin-bottom:12.0pt"><br>
            <br>
            <br>
            -------- Original message --------<br>
            From: Ross Levis &lt;<a moz-do-not-send="true"
              href="mailto:ross@stationplaylist.com">ross@stationplaylist.com</a>&gt;
            <br>
            Date: <br>
            To: 'NZ Borland Developers Group - Delphi List' &lt;<a
              moz-do-not-send="true"
              href="mailto:delphi@listserver.123.net.nz">delphi@listserver.123.net.nz</a>&gt;
            <br>
            Subject: Re: [DUG] StrCopy problem <br>
            <br>
            <br>
            <o:p></o:p></p>
          <div>
            <div>
              <p class="MsoNormal"
                style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
                  style="color:#1F497D">Doesn&#8217;t really help.</span><o:p></o:p></p>
              <p class="MsoNormal"
                style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
                  style="color:#1F497D">&nbsp;</span><o:p></o:p></p>
              <p class="MsoNormal"
                style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
                  style="color:#1F497D">a := 'abcdefghi' does allocate 9
                  bytes of RAM.&nbsp; I can access a and b after it is
                  assigned.&nbsp; The problem is StrCopy crashes.&nbsp; I would
                  expect &#8220;a&#8221; to have the same string as b once this is
                  executed.</span><o:p></o:p></p>
              <p class="MsoNormal"
                style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
                  style="color:#1F497D">&nbsp;</span><o:p></o:p></p>
              <p class="MsoNormal"
                style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
                  style="color:#1F497D">Ross.</span><o:p></o:p></p>
              <p class="MsoNormal"
                style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
                  style="color:#1F497D">&nbsp;</span><o:p></o:p></p>
              <div>
                <div style="border:none;border-top:solid #B5C4DF
                  1.0pt;padding:3.0pt 0cm 0cm 0cm">
                  <p class="MsoNormal"
                    style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><b><span
style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;;color:#1F497D"
                        lang="EN-US">From:</span></b><span
style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;;color:#1F497D"
                      lang="EN-US"> <a moz-do-not-send="true"
                        href="mailto:delphi-bounces@listserver.123.net.nz">delphi-bounces@listserver.123.net.nz</a>
                      [<a moz-do-not-send="true"
                        href="mailto:delphi-bounces@listserver.123.net.nz">mailto:delphi-bounces@listserver.123.net.nz</a>]
                      <b>On Behalf Of </b>Keith Allpress<br>
                      <b>Sent:</b> Sunday, 12 May 2013 10:27 AM<br>
                      <b>To:</b> 'NZ Borland Developers Group - Delphi
                      List'<br>
                      <b>Subject:</b> Re: [DUG] StrCopy problem</span><o:p></o:p></p>
                </div>
              </div>
              <p class="MsoNormal"
                style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
                  style="color:#1F497D">&nbsp;</span><o:p></o:p></p>
              <p class="MsoNormal"
                style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
                  style="color:#1F497D">Perhaps:</span><o:p></o:p></p>
              <p class="MsoNormal"
                style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
                  style="color:#1F497D"><a moz-do-not-send="true"
                    href="http://rvelthuis.de/articles/articles-pchars.html">http://rvelthuis.de/articles/articles-pchars.html</a></span><o:p></o:p></p>
              <p class="MsoNormal"
                style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
                  style="color:#1F497D">&nbsp;</span><o:p></o:p></p>
              <p class="MsoNormal"
                style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
                  style="color:#1F497D">&nbsp;</span><o:p></o:p></p>
              <div>
                <div style="border:none;border-top:solid #E1E1E1
                  1.0pt;padding:3.0pt 0cm 0cm 0cm">
                  <p class="MsoNormal"
                    style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><b><span
                        style="color:#1F497D" lang="EN-US">From:</span></b><span
                      style="color:#1F497D" lang="EN-US"> <a
                        moz-do-not-send="true"
                        href="mailto:delphi-bounces@listserver.123.net.nz">delphi-bounces@listserver.123.net.nz</a>
                      [<a moz-do-not-send="true"
                        href="mailto:delphi-bounces@listserver.123.net.nz">mailto:delphi-bounces@listserver.123.net.nz</a>]
                      <b>On Behalf Of </b>Ross Levis<br>
                      <b>Sent:</b> Sunday, 12 May 2013 2:39 a.m.<br>
                      <b>To:</b> 'NZ Borland Developers Group - Delphi
                      List'<br>
                      <b>Subject:</b> [DUG] StrCopy problem</span><o:p></o:p></p>
                </div>
              </div>
              <p class="MsoNormal"
                style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
                  style="color:#1F497D">&nbsp;</span><o:p></o:p></p>
              <p class="MsoNormal"
                style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
                  style="color:#1F497D">var</span><o:p></o:p></p>
              <p class="MsoNormal"
                style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
                  style="color:#1F497D">&nbsp; a: pChar;</span><o:p></o:p></p>
              <p class="MsoNormal"
                style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
                  style="color:#1F497D">&nbsp; b: pChar;</span><o:p></o:p></p>
              <p class="MsoNormal"
                style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
                  style="color:#1F497D">begin</span><o:p></o:p></p>
              <p class="MsoNormal"
                style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
                  style="color:#1F497D">&nbsp; a := 'abcdefghi';</span><o:p></o:p></p>
              <p class="MsoNormal"
                style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
                  style="color:#1F497D">&nbsp; b := 'jklmnopqr';</span><o:p></o:p></p>
              <p class="MsoNormal"
                style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
                  style="color:#1F497D">&nbsp; StrCopy(a,b);</span><o:p></o:p></p>
              <p class="MsoNormal"
                style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
                  style="color:#1F497D">end;</span><o:p></o:p></p>
              <p class="MsoNormal"
                style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
                  style="color:#1F497D">&nbsp;</span><o:p></o:p></p>
              <p class="MsoNormal"
                style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
                  style="color:#1F497D">Question:&nbsp; Why does this code
                  crash?</span><o:p></o:p></p>
              <p class="MsoNormal"
                style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span
                  style="color:#1F497D">&nbsp;</span><o:p></o:p></p>
            </div>
          </div>
          <p class="MsoNormal"><br>
            <br>
            <br>
            <o:p></o:p></p>
          <pre>_______________________________________________<o:p></o:p></pre>
          <pre>NZ Borland Developers Group - Delphi mailing list<o:p></o:p></pre>
          <pre>Post: <a moz-do-not-send="true" href="mailto:delphi@listserver.123.net.nz">delphi@listserver.123.net.nz</a><o:p></o:p></pre>
          <pre>Admin: <a moz-do-not-send="true" href="http://delphi.org.nz/mailman/listinfo/delphi">http://delphi.org.nz/mailman/listinfo/delphi</a><o:p></o:p></pre>
          <pre>Unsubscribe: send an email to <a moz-do-not-send="true" href="mailto:delphi-request@listserver.123.net.nz">delphi-request@listserver.123.net.nz</a> with Subject: unsubscribe<o:p></o:p></pre>
        </blockquote>
        <p class="MsoNormal"><o:p>&nbsp;</o:p></p>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
NZ Borland Developers Group - Delphi mailing list
Post: <a class="moz-txt-link-abbreviated" href="mailto:delphi@listserver.123.net.nz">delphi@listserver.123.net.nz</a>
Admin: <a class="moz-txt-link-freetext" href="http://delphi.org.nz/mailman/listinfo/delphi">http://delphi.org.nz/mailman/listinfo/delphi</a>
Unsubscribe: send an email to <a class="moz-txt-link-abbreviated" href="mailto:delphi-request@listserver.123.net.nz">delphi-request@listserver.123.net.nz</a> with Subject: unsubscribe</pre>
    </blockquote>
    <br>
  </body>
</html>