August 15th, 2004, 05:01 PM
Join Date: Feb 2004
Time spent in forums: 1 m 7 sec
Reputation Power: 0
Access vilation : pointer to a record
I have the folowing code, where lptNewMessage is a pointer to my record type (PTMessageConv).
lptNewMessage^.sMessage := 'adasdasdas';
lptNewMessage^.sHasNotRead := 'asdasdasds';
I get an access violation error on the 3rd line. Is it because my String exceeds the allocated memory for the pointer? I don't know how the String really works, but shouldn't it take care of it's own memory needs?
Here's my record type :
PTMessageConv = ^TMessageConv;
TMessageConv = class(TObject)
sMessage : String;
sHasNotRead : String;
Edit : If I swap the 2nd and 3rd line of code, it will crash on the 2nd line instead of the 3rd. And if I swap the 2 elements of my definition, it will crash on the 2nd line instead of the 3rd. So it has something to do with the last field of my record.