Hi,
ich steh grad völlig auf dem Schlauch. Ich soll eine Struktur abbilden, die wie folgt aussieht:
TKB_Diagnose_type
-bool ObjEnabled
-string ObjDescr
-8 x bool ObjFUEnabled
-8 x TKB_DiagnoseRow_type
-TKB_DiagnoseRowEn_type
-Byte Nde
-uint RawValue
-int Pos
-ushort Status
-TKB_DiagnoseRowFc_type
-Byte Nde
-ushort Control
-short SetValue
-ushort Status
-ushort ActValue
-ushort Current
Ich wollte das ganze mit Klassen machen, da ich die Daten nachher noch oft verändern muss. Nur - irgendwie bekomme ich keine Hierarchie aufgebaut, bei der alles initialisiert wird. Wenn ich von folgender Struktur ein Objekt anlege, ist nur die Ebene bis Row initialisiert, es gibt auch 8 Row-Elemente, nur die sind alle null.
public class TKB_DiagnoseRowFc_type
{
public Byte Nde;
public ushort Control;
public short SetValue;
public ushort Status;
public ushort ActValue;
public ushort Current;
}
public class TKB_DiagnoseRowEn_type
{
public Byte Nde;
public uint RawValue;
public int Pos;
public ushort Status;
}
public class TKB_DiagnoseRow_type
{
public TKB_DiagnoseRowEn_type En = new TKB_DiagnoseRowEn_type();
public TKB_DiagnoseRowFc_type Fc = new TKB_DiagnoseRowFc_type();
}
public class TKB_Diagnose_type
{
public Boolean ObjEnabled;
public string ObjDescr;
public bool[] ObjFUEnabled = new bool[8];
public TKB_DiagnoseRow_type[] Row = new TKB_DiagnoseRow_type[8];
}
Hilfe!
public class TKB_Diagnose_type
{
void TKB_Diagnose_type()
{
for (int i = 0; i > Row.Length; i++)
{
Row[i] = new TKB_DiagnoseRow_type();
}
}
public Boolean ObjEnabled;
public string ObjDescr;
public bool[] ObjFUEnabled = new bool[8];
public TKB_DiagnoseRow_type[] Row = new TKB_DiagnoseRow_type[8];
}
Hi Ayke,
danke für die schnelle Antwort. Beim Konstruktor musste statt "void" ein "public" rein, die for-Schleife sollte lieber bis < Row.Length zählen nicht >. Mit einer zusätzlichen Klassenverschachtelung wird das ganze zwar nicht sicherer gekapselt, aber übersichtlicher. Oder?
public class TKB_Diagnose_type
{
public Boolean ObjEnabled;
public string ObjDescr;
public bool[] ObjFUEnabled = new bool[8];
public TKB_DiagnoseRow_type[] Row = new TKB_DiagnoseRow_type[8];
public TKB_Diagnose_type()
{
for (int i = 0; i < Row.Length; i++)
Row[i] = new TKB_DiagnoseRow_type();
}
public class TKB_DiagnoseRow_type
{
public TKB_DiagnoseRowEn_type En = new TKB_DiagnoseRowEn_type();
public TKB_DiagnoseRowFc_type Fc = new TKB_DiagnoseRowFc_type();
public class TKB_DiagnoseRowFc_type
{
public Byte Nde;
public ushort Control;
public short SetValue;
public ushort Status;
public ushort ActValue;
public ushort Current;
}
public class TKB_DiagnoseRowEn_type
{
public Byte Nde;
public uint RawValue;
public int Pos;
public ushort Status;
}
}
}
wollte grade zu mittag 😛, deswegen haben Sie die Fehler eingeschlichen. Ob du das verschachteln solltest kann ich dir nicht sagen.