<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii"><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:11.0pt;
        font-family:"Calibri","sans-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;}
p.element10, li.element10, div.element10
        {mso-style-name:element10;
        mso-margin-top-alt:auto;
        margin-right:0cm;
        mso-margin-bottom-alt:auto;
        margin-left:0cm;
        font-size:12.0pt;
        font-family:"Times New Roman","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.EmailStyle21
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.EmailStyle22
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.EmailStyle23
        {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.EmailStyle26
        {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]--></head><body bgcolor=white lang=EN-NZ link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'>I did read that previously a few times. Ok, so I should make A longer by 1 character? I think A is already 10 characters long with a #0 at the end.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'>Anyway, I changed it to the following.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'>a := 'abcdefghixxxx';<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'>b := 'jklmnopqr';<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'>StrCopy(a,b);<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'>Still an access violation in StrCopy.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'><o:p> </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 lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext'>From:</span></b><span lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext'> delphi-bounces@listserver.123.net.nz [mailto:delphi-bounces@listserver.123.net.nz] <b>On Behalf Of </b>David Moorhouse<br><b>Sent:</b> Sunday, 12 May 2013 3:26 PM<br><b>To:</b> delphi@listserver.123.net.nz<br><b>Subject:</b> Re: [DUG] StrCopy problem<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal>Your answer is in the help file<o:p></o:p></p><p class=element10><i>Use StrCopy to copy Source to Dest. StrCopy returns Dest. </i><o:p></o:p></p><p class=element10><i>StrCpy does not perform any length checking. The destination buffer must have room for at least <a href="http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/SysUtils_StrLen@PAnsiChar.html">StrLen</a>(Source)+1 characters. </i><o:p></o:p></p><p class=element10><i>For length checking, use the <a href="http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/SysUtils_StrLCopy@PAnsiChar@PAnsiChar@Cardinal.html">StrLCopy</a> function. </i><o:p></o:p></p><p class=MsoNormal><i><br></i><br>D<br><br><br>On 12/05/13 14:45, 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-size:12.0pt;color:#1F497D'>Doesn’t really help.</span><o:p></o:p></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'> </span><o:p></o:p></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'>a := 'abcdefghi' does allocate 9 bytes of RAM. I can access a and b after it is assigned. The problem is StrCopy crashes. I would expect “a” to have the same string as b once this is executed.</span><o:p></o:p></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'> </span><o:p></o:p></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'>Ross.</span><o:p></o:p></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'> </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 lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> <a href="mailto:delphi-bounces@listserver.123.net.nz">delphi-bounces@listserver.123.net.nz</a> [<a 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> <o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'>Perhaps:</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'><a 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><span style='color:#1F497D'> </span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> </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><b><span lang=EN-US>From:</span></b><span lang=EN-US> <a href="mailto:delphi-bounces@listserver.123.net.nz">delphi-bounces@listserver.123.net.nz</a> [<a 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> <o:p></o:p></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'>var</span><o:p></o:p></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'> a: pChar;</span><o:p></o:p></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'> b: pChar;</span><o:p></o:p></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'>begin</span><o:p></o:p></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'> a := 'abcdefghi';</span><o:p></o:p></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'> b := 'jklmnopqr';</span><o:p></o:p></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'> StrCopy(a,b);</span><o:p></o:p></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'>end;</span><o:p></o:p></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'> </span><o:p></o:p></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'>Question: Why does this code crash?</span><o:p></o:p></p><p class=MsoNormal><span style='font-size:12.0pt;color:#1F497D'> </span><o:p></o:p></p><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><br><br><br><o:p></o:p></span></p><pre>_______________________________________________<o:p></o:p></pre><pre>NZ Borland Developers Group - Delphi mailing list<o:p></o:p></pre><pre>Post: <a href="mailto:delphi@listserver.123.net.nz">delphi@listserver.123.net.nz</a><o:p></o:p></pre><pre>Admin: <a 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 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><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p> </o:p></span></p></div></body></html>