Implementing IInterface works in VCL but not in FMX

This is the forum for miscellaneous technical/programming questions.

Moderator: 2ffat

Implementing IInterface works in VCL but not in FMX

Postby Ahmed Sayed » Tue Nov 19, 2019 8:50 am

Hi All,

I have this interface called "IViewFrame" its implementation is like this:

Code: Select all
    __interface INTERFACE_UUID("{D307ACE9-FE13-4F11-BEEB-A15C908579BC}") IViewFrame : public System::IInterface
    {
    //---------------------------------------------------------------------------
    protected:
    //Setters/Getters
    virtual void __fastcall SetView(TView *Value) = 0;
    virtual TView* __fastcall GetView() = 0;
   
    //---------------------------------------------------------------------------
    public:
    //Fields/Properties
    __property TView *View = {read = GetView, write = SetView};
    //---------------------------------------------------------------------------
    };
    //---------------------------------------------------------------------------
    typedef System::DelphiInterface<IViewFrame> _di_IViewFrame;

Now on VCL this interface is working fine here is the code:
Code: Select all
class TVCLFrame : public TFrame, IViewFrame
{
__published:   // IDE-managed Components

private:
//Fields
TView *FView;
//---------------------------------------------------------------------------
protected:
//Setters/Getters
virtual void __fastcall SetView(TView *Value);
virtual TView* __fastcall GetView();
public:      // User declarations
   __fastcall TVCLFrame(TComponent* Owner);

INTFOBJECT_IMPL_IUNKNOWN(TFrame);
};
//---------------------------------------------------------------------------


But when i do the same thing in Fmx Frame I get a conflict error in "INTFOBJECT_IMPL_IUNKNOWN" line:

Code: Select all
class TFmxFrame : public TFrame, IViewFrame
{
__published:   // IDE-managed Components
   TBindingsList *BindingsList;
   TBindSourceDB *BindSourceDB;
   TBindNavigator *BindNavigator1;
private:   // User declarations
TView *FView;

protected:
//Setters/Getters
virtual void __fastcall SetView(TView *Value);
virtual TView* __fastcall GetView();

public:      // User declarations
   __fastcall TFmxFrame(TComponent* Owner);

INTFOBJECT_IMPL_IUNKNOWN(TFrame); // I get the error here
};
//---------------------------------------------------------------------------
[bcc32 Error] FmxFrameU.h(50): E2113 Virtual function '__stdcall TFmxFrame::Release()' conflicts with base class 'TFmxObject'
Full parser context
FmxFrameU.h(33): class TFmxFrame


Now I looked into TfmxObjct code and found out that there is another method called "Release"

[bcc32 Error] FmxFrameU.h(50): E2113 Virtual function '__stdcall TFmxFrame::Release()' conflicts with base class 'TFmxObject'
Full parser context
FmxFrameU.h(33): class TFmxFrame

that conflicts with the one from IUnkown Interface.

How can i fix this issue i want this interface to work for both VCL and FMX without any troubles

Any help will be appreciated. Thanks in advance
Ahmed Sayed
Top Poster
Top Poster
 
Posts: 31
Joined: Thu Nov 08, 2018 4:12 pm

Re: Implementing IInterface works in VCL but not in FMX

Postby rlebeau » Thu Nov 21, 2019 8:16 pm

See Inheritance and Interfaces: IUnknown and IInterface.

TComponent already implements the IInterface/IUnknown methods for you, so you shouldn't need to implement them manually (via the INTFOBJECT_IMPL_IUNKNOWN macro) in your TFrame class at all. That macro is meant to be used in classes you write from scratch that actually need to implement the IUnknown/IInterface methods directly. VCL/FMX controls don't apply to that.
Remy Lebeau (TeamB)
Lebeau Software
User avatar
rlebeau
BCBJ Author
BCBJ Author
 
Posts: 1616
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA

Re: Implementing IInterface works in VCL but not in FMX

Postby Ahmed Sayed » Fri Nov 22, 2019 5:20 am

Thanks Remy,

But when i remove "INTFOBJECT_IMPL_IUNKNOWN" macro i still get error that i can't create instance of this TFrame Class

Code: Select all
[bcc32 Error] Unit2.h(53): E2352 Cannot create instance of abstract class 'TFmxFrame'
  Full parser context
    Unit2.cpp(6): #include Unit2.h
    Unit2.h(52): parsing: void TestCreate()

[bcc32 Error] Unit2.h(53): E2353 Class 'TFmxFrame' is abstract because of '__stdcall IUnknown::QueryInterface(const _GUID &,void * *) = 0'
  Full parser context
    Unit2.cpp(6): #include Unit2.h
    Unit2.h(52): parsing: void TestCreate()

So it complains about the missing 3 functions of IUnkown, As i mentioned in VCL it works fine with the macro but it does not for Fmx because a method called Release already Exists in TFmxObject.

I tried this in Berlin and Rio both did not work.

If you are saying that TFmxFrame does not need the "INTFOBJECT_IMPL_IUNKNOWN" macro and that it will work how the class should look like then because i tried everything even virtual inheritance.

Thanks
Ahmed Sayed
Top Poster
Top Poster
 
Posts: 31
Joined: Thu Nov 08, 2018 4:12 pm

Re: Implementing IInterface works in VCL but not in FMX

Postby rlebeau » Fri Nov 22, 2019 5:26 pm

Ahmed Sayed wrote:As i mentioned in VCL it works fine with the macro


Because there is no Release() method in VCL's TFrame (but there is one in TForm).

Ahmed Sayed wrote:but it does not for Fmx because a method called Release already Exists in TFmxObject.


Then you need to take up the issue with Embarcadero.

However, I will say that the TFmxObject::Release() method is already deprecated, so it may disappear in a future version. But until then, there is probably nothing you can do about this without changing your code design so that your TFmxFrame class uses encapsulation rather than inheritance to implement its support for the IViewFrame interface. Both TFmxObject::Release() and IUnknown::Release() have no parameters, and methods can't be overloaded on their return value alone.
Remy Lebeau (TeamB)
Lebeau Software
User avatar
rlebeau
BCBJ Author
BCBJ Author
 
Posts: 1616
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA

Re: Implementing IInterface works in VCL but not in FMX

Postby Ahmed Sayed » Sat Nov 23, 2019 8:03 am

Thanks.

But is it possible to use this in my case instead of inheritance:
http://docwiki.embarcadero.com/RADStudi ... %2BBuilder

But the documentation is not clear on how to use something like my interface IViewFrame as a property and how get that interface later for instance like this:
Code: Select all
TControl *FmxControl = (TControl*)Control;

_di_ITextSettings Settings;

FmxControl->GetInterface(Settings);

if (Settings != nullptr)
   {// rest of code


or this will just make me use it as property so there is no need for it in my case?
Ahmed Sayed
Top Poster
Top Poster
 
Posts: 31
Joined: Thu Nov 08, 2018 4:12 pm

Re: Implementing IInterface works in VCL but not in FMX

Postby minas » Sun Nov 24, 2019 12:17 pm

the Cpp Example ,in the following link, maybe could help you

http://docwiki.embarcadero.com/RADStudi ... nd_C%2B%2B
User avatar
minas
BCBJ Guru
BCBJ Guru
 
Posts: 199
Joined: Sat Jul 10, 2004 6:09 am
Location: Greece


Return to Technical

Who is online

Users browsing this forum: No registered users and 16 guests

cron