Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Implementation of interface in TForm descendant


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 0
Petr Vykouk

Posts: 42
Registered: 6/4/00
Implementation of interface in TForm descendant  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 27, 2016 1:34 AM
In example bellow compilation is without error, but in runtime Error: 'Pure virtual function called' is raised

File interface.h

//---------------------------------------------------------------------------
#ifndef InterfaceH
#define InterfaceH

__interface INTERFACE_UUID("{9EB5933E-7556-46FD-A3EB-85163E462809}") ITest : public IInterface
{
private:
protected:
public:
virtual void __fastcall SetTest(int Scale) = 0; // Pure virtual
virtual int __fastcall GetTest(void) = 0; // Pure virtual
__property int Test = { read = GetTest, write = SetTest };
};
typedef System::DelphiInterface<ITest> _di_Test;
#endif
//---------------------------------------------------------------------------

File Unit1.h
//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include "Interface.h"
//---------------------------------------------------------------------------
class TForm1 : public TForm, public ITest
{
__published: // IDE-managed Components
private: // User declarations
void __fastcall SetTest(int Scale) { }; // Override
int __fastcall GetTest(void) {return 1;}; // Override
public: // User declarations
__fastcall TForm1(TComponent* Owner);

};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

File Unit1.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
_di_Test i1;

if (this->GetInterface(i1)) // <====== Error: Pure virtual function called (Win32),
{
i1->Test = 1;

int x = i1->Test;
}
}
//---------------------------------------------------------------------------

Where is mistake? Thanks
(C++ XE8)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02