@@ -830,49 +830,52 @@ private void addSubItemToolStripMenuItem_Click(object sender, EventArgs e)
830830 {
831831 ODentry od = ( ODentry ) selecteditemsub . Tag ;
832832
833- if ( od . parent . objecttype == ObjectType . ARRAY )
833+ if ( od . parent != null )
834+ od = od . parent ;
835+
836+ if ( od . objecttype == ObjectType . ARRAY )
834837 {
835838 ODentry newsub = new ODentry ( ) ;
836- newsub . parent = od . parent ;
837- newsub . datatype = od . parent . datatype ;
838- newsub . accesstype = od . parent . accesstype ;
839- newsub . PDOtype = od . parent . PDOtype ;
839+ newsub . parent = od ;
840+ newsub . datatype = od . datatype ;
841+ newsub . accesstype = od . accesstype ;
842+ newsub . PDOtype = od . PDOtype ;
840843 newsub . index = od . index ;
841844 newsub . objecttype = ObjectType . VAR ;
842- newsub . subindex = ( UInt16 ) od . parent . subobjects . Count ;
843- od . parent . subobjects . Add ( ( UInt16 ) ( od . parent . subobjects . Count ) , newsub ) ;
845+ newsub . subindex = ( UInt16 ) od . subobjects . Count ;
846+ od . subobjects . Add ( ( UInt16 ) ( od . subobjects . Count ) , newsub ) ;
844847
845- UInt16 def = EDSsharp . ConvertToUInt16 ( od . parent . subobjects [ 0 ] . defaultvalue ) ;
848+ UInt16 def = EDSsharp . ConvertToUInt16 ( od . subobjects [ 0 ] . defaultvalue ) ;
846849
847850 def ++ ;
848- od . parent . subobjects [ 0 ] . defaultvalue = def . ToString ( ) ;
851+ od . subobjects [ 0 ] . defaultvalue = def . ToString ( ) ;
849852
850853
851854 }
852855
853- if ( od . parent . objecttype == ObjectType . REC )
856+ if ( od . objecttype == ObjectType . REC )
854857 {
855858 DataType dt = od . datatype ;
856859
857- NewIndex ni = new NewIndex ( eds , dt , od . parent . objecttype , od . parent ) ;
860+ NewIndex ni = new NewIndex ( eds , dt , od . objecttype , od ) ;
858861
859862 if ( ni . ShowDialog ( ) == DialogResult . OK )
860863 {
861864 ODentry newsub = new ODentry ( ) ;
862- newsub . parent = od . parent ;
865+ newsub . parent = od ;
863866 newsub . datatype = ni . dt ;
864- newsub . accesstype = od . parent . accesstype ;
865- newsub . PDOtype = od . parent . PDOtype ;
867+ newsub . accesstype = od . accesstype ;
868+ newsub . PDOtype = od . PDOtype ;
866869 newsub . index = od . index ;
867870 newsub . objecttype = ObjectType . VAR ;
868- newsub . subindex = ( UInt16 ) od . parent . subobjects . Count ;
871+ newsub . subindex = ( UInt16 ) od . subobjects . Count ;
869872 newsub . parameter_name = ni . name ;
870873
871- od . parent . subobjects . Add ( ( UInt16 ) ( od . parent . subobjects . Count ) , newsub ) ;
874+ od . subobjects . Add ( ( UInt16 ) ( od . subobjects . Count ) , newsub ) ;
872875
873- UInt16 def = EDSsharp . ConvertToUInt16 ( od . parent . subobjects [ 0 ] . defaultvalue ) ;
876+ UInt16 def = EDSsharp . ConvertToUInt16 ( od . subobjects [ 0 ] . defaultvalue ) ;
874877 def ++ ;
875- od . parent . subobjects [ 0 ] . defaultvalue = def . ToString ( ) ;
878+ od . subobjects [ 0 ] . defaultvalue = def . ToString ( ) ;
876879 }
877880 }
878881
0 commit comments