delphi - Acces violation on instance variable -


i have 2 class. 1 abstract (xmlnodemanager) , concrete child xmlenpmanager. abstract class definition is:

type   txmlnodemanager = class     public       constructor create(aroot: ixmlnode); virtual; abstract;       function size(): integer;    protected       { sgy alias para strategy }       sgyiterator: integer;       sgyattributes: tstringlist;       sgyroot: ixmlnode;   end; 

and, subclass:

type   txmlenpmanager = class (txmlnodemanager)     public       constructor create(aroot: ixmlnode); override;   end; 

the constructor implemented in subclass, , have next code:

constructor txmlenpmanager.create(aroot: ixmlnode); begin   sgyiterator := 0;   sgyroot := aroot;   self.generateattribs; end; 

whereas size() method implemented in father:

function txmlnodemanager.size(): integer; begin   size := sgyroot.childnodes.count; end; 

when create instance of xmlenpmanager, , pass defined ixmlnode param, , send size() message. program fails (in execution time) acces violation on sgyroot.childnodes.count.

i next check:

function txmlnodemanager.size(): integer; begin   if (assigned(sgyroot))     showmessage('root assigned.')   else     showmessage('root not assigned ???'); end; 

show second alert. im newest in delphi, , suspect interface reference value, unlike objects. correct ?. how solves problem ? ideas ?.

edit: down-casting. have variable of type xmlnodemanager, initilize subclass of xmlnodemanager. this, correct ?. example:

// anode can instance of txmlenpmanager or subclass of txmlnodemanager. procedure txmlfilemanager.setcurrentnode(anode: txmlnodemanager);     begin       // xmcurrentnode of txmlnodemanager type       xmcurrentnode := anode;     end; 

if i'm not mistaken, should call inherited constructor constructor:

constructor txmlenpmanager.create(aroot: ixmlnode); begin   inherited create;   sgyiterator := 0;   sgyroot := aroot;   self.generateattribs; end; 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -