[DUG] StrCopy problem
Ross Levis
ross at stationplaylist.com
Mon May 13 01:45:10 NZST 2013
StrCopy(Dest,Source);
From: delphi-bounces at listserver.123.net.nz
[mailto:delphi-bounces at listserver.123.net.nz] On Behalf Of Cameron Hart
Sent: Sunday, 12 May 2013 11:06 PM
To: NZ Borland Developers Group - Delphi List
Subject: Re: [DUG] StrCopy problem
a := 'abcdefghixxxx';
b := 'jklmnopqr';
StrCopy(a,b);
You made source longer. The dest needs to be strlen(source)+1
a := 'abcdefghi';
b := 'jklmnopqrxxxx';
StrCopy(a,b);
Cameron Hart
Flow Software Limited
cid:image004.jpg at 01CE44FA.D77C3F80
Flow
PO Box 302 768, North Harbour
P
+64 9 476 3569 x910
Auckland 0751, New Zealand
M
+64 21 222 3569
<http://www.flowsoftware.co.nz> www.flowsoftware.co.nz
E
<mailto:cameron.hart at flowsoftware.co.nz> cameron.hart at flowsoftware.co.nz
This message is intended for the addressee named above. It may contain
privileged or confidential information. If you are not the intended
recipient of this message you must not use, copy, distribute or disclose it
to anyone.
P Please consider the environment before printing this email
From: delphi-bounces at listserver.123.net.nz
[mailto:delphi-bounces at listserver.123.net.nz] On Behalf Of Ross Levis
Sent: Sunday, 12 May 2013 5:20 p.m.
To: 'NZ Borland Developers Group - Delphi List'
Subject: Re: [DUG] StrCopy problem
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.
Anyway, I changed it to the following.
a := 'abcdefghixxxx';
b := 'jklmnopqr';
StrCopy(a,b);
Still an access violation in StrCopy.
From: delphi-bounces at listserver.123.net.nz
[mailto:delphi-bounces at listserver.123.net.nz] On Behalf Of David Moorhouse
Sent: Sunday, 12 May 2013 3:26 PM
To: delphi at listserver.123.net.nz
Subject: Re: [DUG] StrCopy problem
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/HelpUpdate
2/EN/html/delphivclwin32/SysUtils_StrLen at PAnsiChar.html> (Source)+1
characters.
For length checking, use the StrLCopy
<http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate
2/EN/html/delphivclwin32/SysUtils_StrLCopy at PAnsiChar@PAnsiChar at 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-bounces at listserver.123.net.nz
[mailto:delphi-bounces at 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-bounces at listserver.123.net.nz
[mailto:delphi-bounces at 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 at listserver.123.net.nz
Admin: http://delphi.org.nz/mailman/listinfo/delphi
Unsubscribe: send an email to delphi-request at listserver.123.net.nz with
Subject: unsubscribe
_____
No virus found in this message.
Checked by AVG - www.avg.com
Version: 2013.0.3336 / Virus Database: 3162/6317 - Release Date: 05/11/13
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://listserver.123.net.nz/pipermail/delphi/attachments/20130513/6dd20f10/attachment-0001.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/jpeg
Size: 648 bytes
Desc: not available
Url : http://listserver.123.net.nz/pipermail/delphi/attachments/20130513/6dd20f10/attachment-0002.jpe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/jpeg
Size: 4211 bytes
Desc: not available
Url : http://listserver.123.net.nz/pipermail/delphi/attachments/20130513/6dd20f10/attachment-0003.jpe
More information about the Delphi
mailing list