#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    4
    Rep Power
    0

    Access violation at address ... in module


    got it
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2006
    Location
    Carlsbad, CA
    Posts
    2,057
    Rep Power
    383
    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
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    4
    Rep Power
    0
    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?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2006
    Location
    Carlsbad, CA
    Posts
    2,057
    Rep Power
    383
    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
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    4
    Rep Power
    0
    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.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2006
    Location
    Carlsbad, CA
    Posts
    2,057
    Rep Power
    383
    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
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    4
    Rep Power
    0
    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!
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2006
    Location
    Carlsbad, CA
    Posts
    2,057
    Rep Power
    383
    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

IMN logo majestic logo threadwatch logo seochat tools logo