- 我有一个 Windows 表单SearchById并且我有一个类UserRecord(用于存储用户名等凭据)(具有实例 obj)在UserRecord.h中定义。
- 现在,当我单击SearchById表单上的Done按钮时,它应该搜索文件 userrecord.txt并将对象的内容(其 id 与文本框 UserId中输入的 id 匹配)复制到文本框tbUserName、tbAddress 和 tbPhoneNumber中。然后,从现有表单中创建一个新表单(我传递要在新表单中显示的参数(从文件中检索的参数))。
- 问题是它们没有被显示,尽管新表单打开时使用相同的 UserId(这很好),但其余的文本框没有显示。(尽管编译很好,没有任何错误或警告)。请帮忙!
代码是:
//Project Name: UserMaintenance //SearchById.h #pragma once namespace UserMaintenance { using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; .. .. .. public ref class SearchById : public System::Windows::Forms::Form { ... private: System::Void btnBackToMainMenu_Click(System::Object^ sender, System::EventArgs^ e); private: System::Void btnDone_Click(System::Object^ sender, System::EventArgs^ e); }; } //SearchById.cpp #include "StdAfx.h" #include "SearchById.h" #include "Main_Menu.h" #include "UserRecord.h" #include <fstream> using namespace std; System::Void UserMaintenance::SearchById::btnDone_Click(System::Object^ sender, System::EventArgs^ e) { int userid = System::Convert::ToInt32(this->tbUserId->Text); String^ username; String^ address; String^ phone; ifstream fusersearch; fusersearch.open("userrecord.txt"); //DO EXCEPTION HANDLING HERE fusersearch.seekg(0,ios::beg); while(fusersearch.read((char*)&obj,sizeof(obj))) { if((obj.UserRecord_compareId(userid))==1) { obj.UserRecord_output(username,address,phone); } } this->tbUserName->Text = username; this->tbAddress->Text = address; this->tbPhoneNumber->Text = phone; SearchById^ sbi_form = gcnew SearchById(); sbi_form->tbUserId->Text = this->tbUserId->Text; sbi_form->tbUserName->Text = this->tbUserName->Text; sbi_form->tbAddress->Text = this->tbAddress->Text; sbi_form->tbPhoneNumber->Text = "hello"; sbi_form->Show(); this->Hide(); } //UserRecord.h #ifndef USERRECORD_H #define USERRECORD_H #include "AddRecord.h" #include "stdafx.h" using namespace std; using namespace System::Windows::Forms; using namespace System; class UserRecord { private: int user_id; char user_name[30]; char user_address[40]; char user_phone[10]; public: int UserRecord_input(int,char*,char*,char*); void UserRecord_output(String^ %,String^ %,String^ %); void UserRecord_update(int); int UserRecord_search(); void UserRecord_report(int); int UserRecord_compareId(int); int UserRecord_compareNAME(char*); }; static UserRecord obj; #endif //UserRecord.cpp #include "stdafx.h" #include "UserRecord.h" #include "AddRecord.h" #include "Main_Menu.h" #include<fstream> #include<iostream> using namespace std; using namespace System::Windows::Forms; using namespace System; void UserRecord::UserRecord_output(String^ %name,String^ %address,String^ %phone) { name = gcnew String(this->user_name); address = gcnew String(this->user_address); phone = gcnew String(this->user_phone); return; }
- 问题可能出在UserRecord.h 和 .cpp中的 void UserRecord::UserRecord_output(String^ %name,String^ %address,String^ %phone) 函数中
mclaren
问问题
651 次