I'm trying to move functions that I have created in my .h files into the .cpp files of my winForm application. I don't really know how to get this to work.
Example code in .h:
void loadCustomerDetails() {
SQLiteConnection^ ObjConnection = gcnew SQLiteConnection("Data Source=SwiftService.db3;");
SQLiteCommand^ ObjCommand = gcnew SQLiteCommand("SELECT * FROM Contact WHERE Type = 'Customer'", ObjConnection);
ObjCommand->CommandType = CommandType::Text;
SQLiteDataAdapter^ ObjDataAdapter = gcnew SQLiteDataAdapter(ObjCommand);
DataSet^ dataSet = gcnew DataSet();
ObjDataAdapter->Fill(dataSet, "Contact");
int posY; //y position for the dynamically created panels
posY = 10;
DataTable ^table = dataSet->Tables["Contact"];
for each (DataRow ^row in table->Rows)
{
Panel ^pnl = gcnew Panel(); //create a panel
//set panel properties
pnl->Location = Point(14, posY);
pnl->Size = System::Drawing::Size(361, 101);
pnl->BorderStyle= BorderStyle::FixedSingle;
pnl->AutoScroll = true;
pnl->Tag = row->default[5]->ToString(); //set Tag for panel so that the contact is unique
//create labels and set properties
Label ^lblName = gcnew Label();
lblName->AutoSize = true;
lblName->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular,
System::Drawing::GraphicsUnit::Point, static_cast<System::Byte>(0)));
lblName->Location = System::Drawing::Point(5, 7);
lblName->Text = row->default[0]->ToString(); //get the item at the index
posY += 110; //increment position y
//add event handler for labels
lblName->Click += gcnew System::EventHandler(this, &Contacts::lbl_Click);
lblTel->Click += gcnew System::EventHandler(this, &Contacts::lbl_Click);
lblMobile->Click += gcnew System::EventHandler(this, &Contacts::lbl_Click);
lblAddress->Click += gcnew System::EventHandler(this, &Contacts::lbl_Click);
pnl->Click += gcnew System::EventHandler(this, &Contacts::pnl_Click); //add event handler for panel
//add controls
pnl->Controls->Add(lblName);
panel2->Controls->Add(pnl);
}
ObjConnection->Close(); //close connection
}
Ok, so that's some code (I've deleted some stuff from it to make it shorter) that I want to move over to the cpp file.
I know that I need to create a prototype function in the .h file. But I get errors such as:
1>.\Contacts.cpp(61) : error C2653: 'Contacts' : is not a class or namespace name
for the line:
lblName->Click += gcnew System::EventHandler(this, &Contacts::lbl_Click);
Also how do I make changes to controls on the form via the cpp file, such as this line of code:
panel2->Controls->Add(pnl);
I'm not asking for anyone to translate the above code. I just need some basics on how to move over to the cpp files.
Thanks.