Delphi Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreDelphi Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 15th, 2004, 04:01 PM
dagn dagn is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 12 dagn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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).

New(lptNewMessage);
lptNewMessage^.sMessage := 'adasdasdas';
lptNewMessage^.sHasNotRead := 'asdasdasds';
Dispose(lptNewMessage);

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;
end;

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.

Reply With Quote
  #2  
Old August 16th, 2004, 03:51 AM
rossM rossM is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2004
Location: England
Posts: 952 rossM User rank is Corporal (100 - 500 Reputation Level)rossM User rank is Corporal (100 - 500 Reputation Level)rossM User rank is Corporal (100 - 500 Reputation Level)rossM User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 23 h 38 m 44 sec
Reputation Power: 13
TMessageConv is a class not a record. If you want a record, replace
Code:
TMessageConv = class(TObject)
with
Code:
TMessageConv = record
and it should work.

Reply With Quote
  #3  
Old August 17th, 2004, 07:12 PM
dagn dagn is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 12 dagn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 7 sec
Reputation Power: 0
What you said makes sense...
But I made the change you suggested, and I have the same error.

Edit : Ok, I was using GetMem instead of New (and Dispose). It seems it's all working fine now. Thanks!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreDelphi Programming > Access vilation : pointer to a record

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap