Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: "Pure virtual function called" riddle, CBuilder 5



Permlink Replies: 1 - Last Post: Feb 28, 2017 3:55 AM Last Post By: Jan Dijkstra Threads: [ Previous | Next ]
Jan Dijkstra

Posts: 206
Registered: 11/4/99
"Pure virtual function called" riddle, CBuilder 5
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 28, 2017 12:22 AM
I have the following class (I stripped out all the non relevant bits)
class PACKAGE TLicCustomDialog : public TCustomApplicationEvents
{
protected:
  bool __fastcall DialogStart (bool genEntries = false);
  int  __fastcall DialogEnd (void);
 
public:
               __fastcall  TLicCustomDialog (TComponent *owner);
  virtual      __fastcall ~TLicCustomDialog (void);
  virtual int  __fastcall  Execute (void);
          int  __fastcall  GenerateEntries (void);
          int  __fastcall  GenerateTransEntries (void);
          bool __fastcall  Show (void);
          int  __fastcall  Hide (void);
          int  __fastcall  Close (void);
};


with the following implementation
int __fastcall TLicCustomDialog::Execute (void)
{
  if (! DialogStart ()) return 0;
 
  FDialogForm->ShowModal ();
 
  return FDialogResult;
}
 
int __fastcall TLicCustomDialog::GenerateTransEntries (void)
{
  if (! DialogStart ()) return 0;
 
  FDialogForm->ShowModal ();
 
  return FDialogResult;
}


As you can see, the implementation of both functions is identical (made that so on purpose, to demonstrate the problem, using copy/paste).

When I call Execute (), everything works as it should. When I call GenerateTransEntries (), the application crashes with "Pure virtual function called". And I'm at a loss as to why that is.

Even weirder, when I replace the body of GenerateTransEntries () with
int __fastcall TLicCustomDialog::GenerateTransEntries (void)
{
  return Execute ();
}

then a call to GenerateTransEntries () doesn't crash, and does what was supposed to happen. I've tried to change the name of the GenerateTransEntries function. I've tried adding other functions, with varying different names (such as ABCDE) with the same body as the Execute () function. Each and every time, I get "Pure virtual function called" thrown in my face. The only time the code in that body doesn't crash, is when I call the Execute function itself.

What is causing the "Pure virtual function called" crash, because I really don't see it.
Jan Dijkstra

Posts: 206
Registered: 11/4/99
Re: "Pure virtual function called" riddle, CBuilder 5
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 28, 2017 3:55 AM   in response to: Jan Dijkstra in response to: Jan Dijkstra
Please ignore. I've found the problem.

The component I've been testing with is a derived component, and it had an override of the Execute function, which bypassed the problem.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02