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

Closed Thread
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 October 21st, 2012, 05:55 PM
simon_66 simon_66 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 4 simon_66 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 54 m 29 sec
Reputation Power: 0
Access violation at address ... in module

got it

Reply With Quote
  #2  
Old October 21st, 2012, 07:02 PM
clivew clivew is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 2,045 clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 37 m
Reputation Power: 382
Code:
   user := TUser.Create;


Also FYI:
1. Delphi convention is to name private fields of a class (but not other variables) with an initial "F" not "_".
e.g.
FUsername : String;
FPosts : integer;

2. Delphi will automatically initialize private class fields during object creation.
Strings to empty string.
integers to 0.
booleans to False.

No need to initialize them in the create method unless you want to initialize them to
some other value. But BEWARE this only applies to class fields. All other variables do
need initializing.
e.g. method variables and stand alone procedure and function variables.

Clive

Reply With Quote
  #3  
Old October 22nd, 2012, 05:05 PM
simon_66 simon_66 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 4 simon_66 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 54 m 29 sec
Reputation Power: 0
Quote:
Originally Posted by clivew
Code:
   user := TUser.Create;


Also FYI:
1. Delphi convention is to name private fields of a class (but not other variables) with an initial "F" not "_".
e.g.
FUsername : String;
FPosts : integer;

2. Delphi will automatically initialize private class fields during object creation.
Strings to empty string.
integers to 0.
booleans to False.

No need to initialize them in the create method unless you want to initialize them to
some other value. But BEWARE this only applies to class fields. All other variables do
need initializing.
e.g. method variables and stand alone procedure and function variables.

Clive


I just added those on the CTOR for testing, I added this there:

Code:
FXMLDoc := TXMLDocument.Create(nil);


Now when I get here it crashes

Code:
XMLNode := FXMLDoc.Node.ChildNodes['user'];


XMLNode is a IXMLNode and FXMLDoc is a TXMLDocument

My error is

Code:
Project2.exe raised exception class EInvalidPointer with message 'Invalid pointer operation'.


My guess is that I need to initialize XMLNode or is it something else?

Reply With Quote
  #4  
Old October 22nd, 2012, 06:19 PM
clivew clivew is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 2,045 clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 37 m
Reputation Power: 382
I have not done any testing but I think the code is more like:
Code:
XMLNode := FXMLDoc.ChildNodes,FindNode('user');


Remember, ChildNodes only contains the immediate child nodes of FXMLDoc and FindNode
only looks through the nodes at that level.

You also always need to remember that if FindNode fails then XMLNode will be nil.

Clive

Reply With Quote
  #5  
Old October 22nd, 2012, 06:39 PM
simon_66 simon_66 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 4 simon_66 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 54 m 29 sec
Reputation Power: 0
Quote:
Originally Posted by clivew
I have not done any testing but I think the code is more like:
Code:
XMLNode := FXMLDoc.ChildNodes,FindNode('user');


Remember, ChildNodes only contains the immediate child nodes of FXMLDoc and FindNode
only looks through the nodes at that level.

You also always need to remember that if FindNode fails then XMLNode will be nil.

Clive


Nope, still crashes, same error.

I tried this code using a TXMLDocument from the tool palette. It works fine, since I'm writing these in a function I don't have access to it.




=================UPDATE==============

The problem is that I had FXMLDoc as a TXMLDocument and not an IXMLDocument.

Reply With Quote
  #6  
Old October 22nd, 2012, 07:14 PM
clivew clivew is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 2,045 clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 37 m
Reputation Power: 382
You probably need to post something more comprehensive for us to help further.
(Someone smarter than me might still help).

From the snippets you post, I, myself, can not see where the invalid pointer operation is raised.

Clive

Reply With Quote
  #7  
Old October 22nd, 2012, 08:09 PM
simon_66 simon_66 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 4 simon_66 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 54 m 29 sec
Reputation Power: 0
Quote:
Originally Posted by clivew
You probably need to post something more comprehensive for us to help further.
(Someone smarter than me might still help).

From the snippets you post, I, myself, can not see where the invalid pointer operation is raised.

Clive


I wrote this

Code:
Now when I get here it crashes

Code:
XMLNode := FXMLDoc.Node.ChildNodes['user'];


XMLNode is a IXMLNode and FXMLDoc is a TXMLDocument

My error is

Code:
Project2.exe raised exception class EInvalidPointer with message 'Invalid pointer o


I said the Error was caused here and what it said, and the type of the variables.

Not sure how much more I could have posted.


Also, I forgot to say thanks for your help!

Reply With Quote
  #8  
Old October 22nd, 2012, 11:16 PM
clivew clivew is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 2,045 clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 37 m
Reputation Power: 382
Nice of you to say thanks - especially as I did not provide a complete answer.
The problem might originate somewhere else and only surface here.

I have similar code (but using the syntax I substituted earlier) that works fine for me.

You could try breaking the code into pieces to see exactly where the error shows itself.
Code:

var
  nodesList: IXMLNodeList;
begin
    XMLNode := FXMLDoc.DocumentElement;
    nodesList := XMLNode.ChildNodes;
    XMLNode :=  nodesList.FindNode('user');
end;


Clive

Reply With Quote
Closed Thread

Viewing: Dev Shed ForumsProgramming Languages - MoreDelphi Programming > Access violation at address ... in module

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