| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 
 | class CFirstImpl: public IFirstInterface
{
public:
  int A() {return -1;}
};
 
class CFirstImplPhase2: public CFirstImpl
{
public:
  int B() {return -22;}
};
 
class CSecondImpl: public CFirstImplPhase2, public ISecondInterface
{
public:
  int C() {return -333;}
  int D() {return -4444;}
};
 
class CSecondImplReA: public CSecondImpl
{
public:
  int A() {return 11111;}
  int C() {return -333;}
  int D() {return -4444;}
};
 
 
class TFirstImpl: public TObject, public IFirstInterface
{
public:
  int A() {return -1;}
};
 
class TFirstImplPhase2: public TFirstImpl
{
public:
  int B() {return -22;}
};
 
class TSecondImpl: public TFirstImplPhase2, public ISecondInterface
{
public:
  int C() {return -333;}
  int D() {return -4444;}
};
 
class TSecondImplReC: public TSecondImpl
{
public:
  int C() {return 333333;}
};
 
class TSecondBisImpl: public IFirstInterface, public ISecondInterface
{
public:
  int A() {return -1;}
  int B() {return -22;}
  int C() {return -333;}
  int D() {return -4444;}
};
 
class TSecondBisImplReAC: public TSecondBisImpl
{
public:
  int A() {return 11111;}
  int C() {return 333333;}
};
 
class TFirstNoImpl: public TObject, public IFirstInterface
{
};
 
class TFirstNoImplPhase2: public TFirstNoImpl
{
public:
  int A() {return -1;}
  int B() {return -22;}
};
 
__interface INTERFACE_UUID ("{F95FFF42-F65A-4C3E-99D0-468658ED5641}") IFirstDelphiInterface : public IInterface
{
public:
  virtual int __stdcall A() = 0;
  virtual int __stdcall B() = 0;
};
typedef System::DelphiInterface<IFirstDelphiInterface> _di_IFirstDelphiInterface; // DelphiInterface
 
__interface INTERFACE_UUID ("{150AA670-7C9D-4CE7-BE7A-C5AC4CB31DEF}") ISecondDelphiInterface : public IInterface
{
public:
  virtual int __stdcall C() = 0;
  virtual int __stdcall D() = 0;
};
typedef System::DelphiInterface<ISecondDelphiInterface> _di_ISecondDelphiInterface; // DelphiInterface
 
 
class TFirstDelphiImpl: public TInterfacedObject, public IFirstDelphiInterface
{
public:
  virtual int __stdcall A() {return -1;}
 
  virtual HRESULT __stdcall QueryInterface(const GUID& IID, void **Obj){return TInterfacedObject::QueryInterface(IID, (void *)Obj);}
  virtual ULONG __stdcall AddRef() {return TInterfacedObject::_AddRef();}
  virtual ULONG __stdcall Release() {return TInterfacedObject::_Release();}
};
 
class TFirstDelphiImplPhase2: public TFirstDelphiImpl
{
public:
  virtual int __stdcall A() {return -11111;}
  virtual int __stdcall B() {return -22;}
};
 
 
//---------------------------------------------------------------------------
void __fastcall TLanguageBasicsForm::BtnInterfaceSeparateImplementsClick(TObject *Sender)
{
  OutputDebugString("C++ Pur A et B");
  IFirstInterface* ObjC = new CFirstImplPhase2();
  OutputDebugString(Format("A : %d - B : %d", ARRAYOFCONST((ObjC->A(), ObjC->B()))).c_str());
  delete ObjC;
 
  OutputDebugString("TObject A pas B");
  IFirstInterface* ObjVCL = new TFirstImplPhase2();
  OutputDebugString(Format("A : %d", ARRAYOFCONST((ObjVCL->A()))).c_str());
  // B() plantera : Pure virtual function called
  // Le programme sera probablement totalement dans les choux (CTRL + F2 pour quitter)
  OutputDebugString("B plante !");
  // OutputDebugString(Format("B : %d", ARRAYOFCONST((ObjVCL->B()))).c_str());
  delete (TFirstImplPhase2*)ObjVCL;
 
  OutputDebugString("TObject ni A ni B");
  IFirstInterface* ObjVCLNo = new TFirstNoImplPhase2();
  // A() et B() planteront : Pure virtual function called
  // Le programme sera probablement totalement dans les choux (CTRL + F2 pour quitter)
  OutputDebugString("A plante !");
  // OutputDebugString(Format("A : %d", ARRAYOFCONST((ObjVCLNo->A()))).c_str());
  OutputDebugString("B plante !");
  // OutputDebugString(Format("B : %d", ARRAYOFCONST((ObjVCLNo->B()))).c_str());
  delete (TFirstNoImplPhase2*)ObjVCLNo;
 
  OutputDebugString("C++ Pur A, B, C et D");
  CSecondImpl* ObjC2 = new CSecondImpl();
  IFirstInterface* IC = ObjC2;
  ISecondInterface* IC2 = ObjC2;
  OutputDebugString(Format("A : %d - B : %d - C : %d - D : %d", ARRAYOFCONST((IC->A(), IC->B(), IC2->C(), IC2->D()))).c_str());
  delete ObjC2;
 
  OutputDebugString("C++ Pur Re A, B, C et D");
  CSecondImpl* ObjC2ReA = new CSecondImplReA();
  IFirstInterface* ICReA = ObjC2ReA;
  ISecondInterface* ICReA2 = ObjC2ReA;
  OutputDebugString(Format("A : %d - B : %d - C : %d - D : %d", ARRAYOFCONST((ICReA->A(), ICReA->B(), ICReA2->C(), ICReA2->D()))).c_str());
  delete ObjC2ReA;
 
  OutputDebugString("TObject Pur A pas B mais C et D");
  TSecondImpl* ObjVCL2 = new TSecondImpl();
  IFirstInterface* IVCL = ObjVCL2;
  ISecondInterface* IVCL2 = ObjVCL2;
  OutputDebugString(Format("A : %d", ARRAYOFCONST((IVCL->A()))).c_str());
  // OutputDebugString(Format("B : %d", ARRAYOFCONST((IVCL->B()))).c_str());
  OutputDebugString("B plante !");
  OutputDebugString(Format("C : %d", ARRAYOFCONST((IVCL2->C()))).c_str());
  OutputDebugString(Format("D : %d", ARRAYOFCONST((IVCL2->D()))).c_str());
  delete ObjVCL2;
 
  OutputDebugString("TObject Pur A pas B mais Re C et D");
  TSecondImpl* ObjVCLReC2 = new TSecondImplReC();
  IFirstInterface* IVCLReC = ObjVCLReC2;
  ISecondInterface* IVCLReC2 = ObjVCLReC2;
  OutputDebugString(Format("A : %d", ARRAYOFCONST((IVCLReC->A()))).c_str());
  // OutputDebugString(Format("B : %d", ARRAYOFCONST((IVCLReC->B()))).c_str());
  OutputDebugString("B plante !");
  OutputDebugString(Format("C : %d", ARRAYOFCONST((IVCLReC2->C()))).c_str());
  OutputDebugString(Format("D : %d", ARRAYOFCONST((IVCLReC2->D()))).c_str());
  delete ObjVCLReC2;
 
  OutputDebugString("TObject A, B, C et D");
  TSecondBisImpl* ObjBis = new TSecondBisImpl();
  IFirstInterface* IBis = ObjBis;
  ISecondInterface* IBis2 = ObjBis;
  OutputDebugString(Format("A : %d - B : %d - C : %d - D : %d", ARRAYOFCONST((IBis->A(), IBis->B(), IBis2->C(), IBis2->D()))).c_str());
  delete ObjBis;
 
  OutputDebugString("TObject Pur B et C ainsi que Re A et Re C");
  TSecondBisImpl* ObjBisReAC = new TSecondBisImplReAC();
  IFirstInterface* IBisReAC = ObjBisReAC;
  ISecondInterface* IBisReAC2 = ObjBisReAC;
  OutputDebugString(Format("A : %d - B : %d - C : %d - D : %d", ARRAYOFCONST((IBisReAC->A(), IBisReAC->B(), IBisReAC2->C(), IBisReAC2->D()))).c_str());
  delete ObjBisReAC;
 
  OutputDebugString("DelphiInterface A et B");
  TFirstDelphiImplPhase2* ObjVCLDIImpl = new TFirstDelphiImplPhase2();
  OutputDebugString(Format("Direct A : %d", ARRAYOFCONST((ObjVCLDIImpl->A()))).c_str());
  OutputDebugString(Format("Direct B : %d", ARRAYOFCONST((ObjVCLDIImpl->B()))).c_str());
 
  _di_IFirstDelphiInterface ObjVCLDI = ObjVCLDIImpl;
  OutputDebugString(Format("A : %d", ARRAYOFCONST((ObjVCLDI->A()))).c_str());
  OutputDebugString("B plante !");
  // OutputDebugString(Format("B : %d", ARRAYOFCONST((ObjVCLDI->B()))).c_str());
} |