Hallo zusammen ich habe folgendes problem, ich muss eine art Datenbank für eine projekt haben. Diese soll mir Informationen für das Programm aus einer Datei zur Verfügung stellen, dabei tritt immer der Fehler "Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt" in der mscorlib. Woran könnte das liegen?
Der Code:
Danke schon mal
MfG
Der Code:
Code:
ref class database{
public: explicit database(void){
this->init_tables();
};
private:
array<String^> ^Poly;
array<String^> ^Name;
array<String^> ^alpha_t;
array<String^> ^lbuffer;
String^ file;
bool init_tables(void){
// lade daten aus datein und speichere sie in vectoren
String^ wkstb = System::Environment::CurrentDirectory->ToString() + "\\db\\" + "werkstoffdb.ktp";
bool opend;
try{
StreamReader^ dbfile = File::OpenText(wkstb);
opend = true;
String^ buffer;
int rows=0;
while((buffer = dbfile->ReadLine()) != nullptr){
rows++;
buffer += "\n";
}
// Split Line->Polyval & Name & alpha T
array<Char>^splitc = {'\n'};
array<Char>^splitp = {'%'};
array<Char>^splitPoly = {' '};
// Split Line
array<String^>^ lines = buffer->Split(splitc);
this->lbuffer = lines;
// Split Lines in Parts
if(rows>0){
array<String^>^tpoly;
array<String^>^tname;
array<String^>^tat;
//tpoly->Length = rows;
for(int i=0;i<rows;i++){
array<String^>^Line = lines[i]->Split(splitp);
tpoly[i] = Line[0];
tname[i] = Line[1];
tat[i] = Line[2];
}
this->alpha_t = tat;
this->Name = tname;
this->Poly = tpoly;
}
}
catch(Exception^ e){
if(dynamic_cast<FileNotFoundException^>(e)){
opend = false;
MessageBox::Show("Öffnen der Werkstoffdatenbank fehlgeschlagen.\n"+e->Message,"Datei nicht gefunden",MessageBoxButtons::RetryCancel,MessageBoxIcon::Error);
}
else{
opend = false;
MessageBox::Show(e->Message->ToString()+ e->Source->ToString(),"Lese Fehler",MessageBoxButtons::OK,MessageBoxIcon::Error);
}
}
return opend;
};
public:
vector<double> getPolyn(String^ name){
vector<double> ret;
array<String^>^polyp;
array<Char>^ splits = {' '};
int k;
for(int i=0;i<this->Name->Length;i++){
if(this->Name[i] == name){
k=i;
break;
}
}
polyp = this->Poly[k]->Split(splits);
for(int i=0;i<polyp->Length;i++){
ret.push_back(Convert::ToDouble(polyp[i]));
}
return ret;
}
array<String^>^ getNames(void){
return this->Name;
}
bool delEntry(String^ pName){
// Eintrag löschen
array<Char>^ splitp = {'%'};
bool ret = false;
for(int i=0;i<this->lbuffer->Length;i++){
array<String^>^tmp = this->lbuffer[i]->Split(splitp);
if(tmp[1] == pName){
this->lbuffer[i] == "";
ret = true;
}
}
return ret;
}
bool addEntry(String^ wName,String^ wPoly,String^ wAt){
// Eintrag hinzufügen
return true;
}
bool saveData(void){
bool written = false;
try{
StreamWriter^ ostream = gcnew StreamWriter(this->file);
for(int i=0;i<this->lbuffer->Length;i++){
if(this->lbuffer[i] != ""){
ostream->WriteLine(this->lbuffer[i]);
}
}
ostream->Close();
written = true;
}
catch(Exception^ e){
if(dynamic_cast<FileNotFoundException^>(e)){
written = false;
MessageBox::Show("Öffnen der Werkstoffdatenbank fehlgeschlagen.\n"+e->Message,"Datei nicht gefunden",MessageBoxButtons::RetryCancel,MessageBoxIcon::Error);
}
else{
written = false;
MessageBox::Show(e->Message->ToString(),"Schreib Fehler",MessageBoxButtons::OK,MessageBoxIcon::Error);
}
}
// nach änderungen daten speichern
return written;
}
};
Danke schon mal

MfG