1
votes

I've a document class which has an object which is a connection to a database. The document class has a dialog box which is spawned from a menu, which contains a combo box. I'm currently using OnInitDialog to set the items in the combo box but want to use the database connection.

What is the best way of supplying the database connection object to the Dialog box object? I don't think I can pass it in as an argument, and if I supply it after construction, I might have missed the call to the OnInitDialog. Is there a way of finding the parent object and calling a getMethod to obtain the database object or am I on the wrong track altogether and should be attempting something completely different?

Thanks for your help, James

3

3 Answers

2
votes

Normally you would subclass the dialog to create a custom constructor which includes whatever objects you want to work on e.g. your database object.

1
votes

You should pass the database connection object in the dialog's constructor. Modify the dialog constructor or add another constructor accordingly. You may declare other plain constructors of the dialog as private so passing on the db connection becomes a requirement for the dialog.

0
votes

I am not sure about architecture you are referring i.e. Dialog box inside the document class but I think you can add a member variable for database connection inside dialog box class and then set the db connection varaible in your dialog box constructor or dlg->dbConnection = dbConn; before calling DoModal or ShowWindow