The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> Delphi Programming
|
Access violation at address ... in module
Discuss Access violation at address ... in module in the Delphi Programming forum on Dev Shed. Access violation at address ... in module Delphi Programming forum discussing Delphi related topics including Kylix, C++ Builder, and more. Delphi is a high-performance language, originally based on the PASCAL language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

October 21st, 2012, 05:55 PM
|
|
Registered User
|
|
Join Date: Oct 2012
Posts: 4
Time spent in forums: 54 m 29 sec
Reputation Power: 0
|
|
|
Access violation at address ... in module
got it
|

October 21st, 2012, 07:02 PM
|
|
Contributing User
|
|
Join Date: Jan 2006
Location: Carlsbad, CA
|
|
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
|

October 22nd, 2012, 05:05 PM
|
|
Registered User
|
|
Join Date: Oct 2012
Posts: 4
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?
|

October 22nd, 2012, 06:19 PM
|
|
Contributing User
|
|
Join Date: Jan 2006
Location: Carlsbad, CA
|
|
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
|

October 22nd, 2012, 06:39 PM
|
|
Registered User
|
|
Join Date: Oct 2012
Posts: 4
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.
|

October 22nd, 2012, 07:14 PM
|
|
Contributing User
|
|
Join Date: Jan 2006
Location: Carlsbad, CA
|
|
|
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
|

October 22nd, 2012, 08:09 PM
|
|
Registered User
|
|
Join Date: Oct 2012
Posts: 4
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! 
|

October 22nd, 2012, 11:16 PM
|
|
Contributing User
|
|
Join Date: Jan 2006
Location: Carlsbad, CA
|
|
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
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|