Your answer is in the help file
/Use StrCopy to copy Source to Dest. StrCopy returns Dest. /
//
/StrCpy does not perform any length checking. The destination buffer
must have room for at least //StrLen
<http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/sysutils_str...@pansichar.html>//(Source)+1
characters. /
//
/For length checking, use the //StrLCopy
<http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/SysUtils_StrLCopy@PAnsiChar@pansic...@cardinal.html>//function.
/
///**//
/
D
On 12/05/13 14:45, Ross Levis wrote:
Doesn't really help.
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.
Ross.
*From:*delphi-boun...@listserver.123.net.nz
[mailto:delphi-boun...@listserver.123.net.nz] *On Behalf Of *Keith
Allpress
*Sent:* Sunday, 12 May 2013 10:27 AM
*To:* 'NZ Borland Developers Group - Delphi List'
*Subject:* Re: [DUG] StrCopy problem
Perhaps:
http://rvelthuis.de/articles/articles-pchars.html
*From:*delphi-boun...@listserver.123.net.nz
<mailto:delphi-boun...@listserver.123.net.nz>
[mailto:delphi-boun...@listserver.123.net.nz] *On Behalf Of *Ross Levis
*Sent:* Sunday, 12 May 2013 2:39 a.m.
*To:* 'NZ Borland Developers Group - Delphi List'
*Subject:* [DUG] StrCopy problem
var
a: pChar;
b: pChar;
begin
a := 'abcdefghi';
b := 'jklmnopqr';
StrCopy(a,b);
end;
Question: Why does this code crash?
_______________________________________________
NZ Borland Developers Group - Delphi mailing list
Post: delphi@listserver.123.net.nz
Admin: http://delphi.org.nz/mailman/listinfo/delphi
Unsubscribe: send an email to delphi-requ...@listserver.123.net.nz with
Subject: unsubscribe
_______________________________________________
NZ Borland Developers Group - Delphi mailing list
Post: delphi@listserver.123.net.nz
Admin: http://delphi.org.nz/mailman/listinfo/delphi
Unsubscribe: send an email to delphi-requ...@listserver.123.net.nz with
Subject: unsubscribe