This does work.

 

GetMem(a,10);

GetMem(b,10);

StrCopy(a,'abcdefghi');

StrCopy(b,'jklmnopqr');

StrCopy(a,b);

 

I don’t get why this is necessary when a := 'abcdefghi' should do the same 
thing, but I’ll need to make some changes.

 

From: [email protected] 
[mailto:[email protected]] On Behalf Of Ross Levis
Sent: Sunday, 12 May 2013 5:31 PM
To: 'NZ Borland Developers Group - Delphi List'
Subject: Re: [DUG] StrCopy problem

 

I did see a & b had a pointer address allocated.  It looked like a normal 
pointer address range.  I’ll try allocating 10 bytes to a later and see what 
happens.

 

Ross.

 

From: [email protected] 
[mailto:[email protected]] On Behalf Of Bevan Edwards
Sent: Sunday, 12 May 2013 4:48 PM
To: [email protected]
Subject: Re: [DUG] StrCopy problem

 

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?

 

Have you tried allocating 10 bytes of memory to 'a' and then using StrCopy?

 

Have you run the debugger and checked where the PChars 'a' and 'b' are pointing 
to before StrCopy?

 




-------- Original message --------
From: Ross Levis <[email protected]> 
Date: 
To: 'NZ Borland Developers Group - Delphi List' <[email protected]> 
Subject: Re: [DUG] StrCopy problem 

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: [email protected] 
[mailto:[email protected]] 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: [email protected] 
[mailto:[email protected]] 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: [email protected]
Admin: http://delphi.org.nz/mailman/listinfo/delphi
Unsubscribe: send an email to [email protected] with 
Subject: unsubscribe

Reply via email to