我正在編寫一個調用一些erp類/函數(erp已經過時並且沒有任何支持的程序)的程序。我在定義「對象」時遇到了困難,並希望在這方面提供一些幫助。在此先感謝C#對象類型 - 對象引用未設置爲對象的實例
我有一個類typeUDDBTble
(定義如下)。
我的編碼是。
typeUDDBTbl UDDB = new typeUDDBTbl();
UDDB.name = "xxxx";
UDDB.Rec = new typeRec[1];
// Edited, incorrect code
// UDDB[0].Items = new typeFld[1];
UDDB.Rec[0].Items = new typeFld[1];
Items是一個對象數組。我試着用new Object[1]
,或其他type(typeFld)
,但都得到
對象引用不設置到對象
任何想法如何,我可以解決這個問題的一個實例?
定義:
public partial class typeUDDBTbl : object, System.ComponentModel.INotifyPropertyChanged
{
private typeRec[] recField;
private string nameField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("Rec", Order = 0)]
public typeRec[] Rec
{
get
{
return this.recField;
}
set
{
this.recField = value;
this.RaisePropertyChanged("Rec");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute(DataType = "token")]
public string name
{
get
{
return this.nameField;
}
set
{
this.nameField = value;
this.RaisePropertyChanged("name");
}
}
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string propertyName)
{
System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
if ((propertyChanged != null))
{
propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}
public partial class typeRec : object, System.ComponentModel.INotifyPropertyChanged
{
private object[] itemsField;
private string dummyField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("Fld", typeof(typeFld), Order = 0)]
[System.Xml.Serialization.XmlElementAttribute("LangFld", typeof(typeLangFld), Order = 0)]
public object[] Items
{
get
{
return this.itemsField;
}
set
{
this.itemsField = value;
this.RaisePropertyChanged("Items");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute(DataType = "token")]
public string dummy
{
get
{
return this.dummyField;
}
set
{
this.dummyField = value;
this.RaisePropertyChanged("dummy");
}
}
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string propertyName)
{
System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
if ((propertyChanged != null))
{
propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}
public partial class typeFld : object, System.ComponentModel.INotifyPropertyChanged
{
private string nameField;
private string valueField;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute(DataType = "token")]
public string name
{
get
{
return this.nameField;
}
set
{
this.nameField = value;
this.RaisePropertyChanged("name");
}
}
/// <remarks/>
[System.Xml.Serialization.XmlTextAttribute()]
public string Value
{
get
{
return this.valueField;
}
set
{
this.valueField = value;
this.RaisePropertyChanged("Value");
}
}
謝謝,我錯過了UDDB.Rec [0] = new typeRec();感謝您的幫助 – Glen 2013-04-10 04:05:09
不客氣。 – 2013-04-10 11:47:08