Link to home
Start Free TrialLog in
Avatar of MooDave
MooDave

asked on

beginner: derived TDialog classes

Please excuse the elementary nature of this question, but I'm just starting. I'm learning object construction and inheritance using Borland C++ v5.01. I've encountered a problem with derived classes. The plan is to derive a class from TDialog, which brings up an address book dialog box with a listbox containing a list of names, a data display area which displays the address information for whichever name is selected from the list and some buttons to perform various operations upon the records listed in the dialog's listbox (add a record, delete a record, edit a record, etc.).

The first derived class is constructed as such:

// Address Book dialog box class
class TAddressBookDialog : public TDialog
{
public:
   TAddressBookDialog(TWindow* parent, TResId resId)
    : TDialog(parent, resId),
      TWindow(parent)  { }
};


No problem here. Everything works as expected. The trouble arises when I try to derive another class from TAddressBookDialog (to create an ADD RECORD, DELETE RECORD, ETC. dialog, which uses information from TAddressBookDialog). I am constructing the derived
class as such:

// Delete a record dialog box class
class TDeleteRecordDialog : public TAddressBookDialog
{
public:
   TDeleteRecordDialog(TWindow* parent, TResId resId)
    : TAddressBookDialog(parent, resId),
      TDialog(parent, resId),
      TWindow(parent)  { }
};


The error I receive is: "TDialog is not an unambiguous base class of TDeleteRecordDialog."

When I remove the TDialog reference, it reads as such:

// Delete a record dialog box class
class TDeleteRecordDialog : public TAddressBookDialog
{
public:
   TDeleteRecordDialog(TWindow* parent, TResId resId)
    : TAddressBookDialog(parent, resId),
      TWindow(parent)  { }
};


When written this way, the project compiles, but when I activate the DELETE RECORD dialog, I get the following CPU error:

Thread Stopped
 Fault: access violation at 0x507f24:
 read of address 0xfffffff

Can you tell me what I'm missing, here? Any help (or a point in the proper direction) would be appreciated.

Dave Parks
parks@cfw.com
ASKER CERTIFIED SOLUTION
Avatar of LucHoltkamp
LucHoltkamp

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MooDave
MooDave

ASKER

Thanks for answering my question. I have, however, tried the suggested solution. Your suggestion would have the second derived class read:

class TDeleteRecordDialog : public TAddressBookDialog
{
public:
   TDeleteRecordDialog(TWindow* parent, TResId resId)
    : TAddressBookDialog(parent, resId)  { }
};


This solution nets me the same CPU error as when I removed the TDialog ancestor alone:

Thread Stopped
 Fault: access violation at 0x507f24:
 read of address 0xfffffff

Any other thoughts? Thanks again for the help.
Dave

I've written, compiled  and tested some code according to your class hierarchy, it runs perfectly. The runtime error you get is due to a NULL pointer assignent somewhere. The C++ code that runs:

#include <owl\pch.h>

class TAddressBookDialog : public TDialog
{
public:
  TAddressBookDialog(TWindow* parent, TResId resId)
         : TDialog(parent, resId)  { }
};

class TDeleteRecordDialog : public TAddressBookDialog
{
public:
  TDeleteRecordDialog(TWindow* parent, TResId resId)
   : TAddressBookDialog(parent, resId) { }
};

class TestApp : public TApplication {
  public:
    TestApp() : TApplication() {}

    void InitMainWindow()
    {
      TFrameWindow* fw (new TFrameWindow(0, "Sample ObjectWindows Program"));
      SetMainWindow(fw);
      TDeleteRecordDialog* DelDialog(new TDeleteRecordDialog(fw, "DIALOG_1"));
      DelDialog->Execute();
    }
};

int
OwlMain(int /*argc*/, char* /*argv*/ [])
{
  return TestApp().Run();
}

The applet needs a resource file with a dialog DIALOG_1:

DIALOG_1 DIALOG 0, 0, 240, 120
STYLE DS_MODALFRAME | DS_3DLOOK | DS_CONTEXTHELP | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION ""
FONT 8, "MS Sans Serif"
{
 CONTROL "OK", IDOK, "BUTTON", BS_PUSHBUTTON | BS_CENTER | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 186, 6, 50, 14
 CONTROL "Cancel", IDCANCEL, "BUTTON", BS_PUSHBUTTON | BS_CENTER | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 186, 26, 50, 14
 CONTROL "Help", IDHELP, "BUTTON", BS_PUSHBUTTON | BS_CENTER | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 186, 46, 50, 14
}

Hope this'll help you out, good luck,
.luc.

PS: there's an OWL topic group!