Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2010-04

Implementing an interface force me to add _AddRef, _Release

10 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Zaher Dirkey
IMyIntf = interface
  function GetValue: Variant;
end;

TMyObject=(TList, IMyIntf)
....
end;

Can not compile becuase it need to add this functions to TMyObject

         function QueryInterface(const iid : tguid;out obj) : longint;stdcall;
         function _AddRef : longint;stdcall;
         function _Release : longint;stdcall;

While i am not inherit IMyIntf from IUnknown or IInterface, Is there a way to not add unnecessary functions (for me at least).

Sorry for my bad English, and Thanks in advance.

Zaher Dirkey

Reply by email

Michael Van Canneyt
to Zaher Dirkey
Zaher Dirkey wrote 16 lines
IMyIntf = interface function GetValue: Variant; end; TMyObject=(TList, IMyIntf) .... end; Can not compile becuase it need to add this functions to TMyObject function QueryInterface(const iid : tguid;out obj) : longint;stdcall; function _AddRef : longint;stdcall; function _Release : longint;stdcall; While i am not inherit IMyIntf from IUnknown or IInterface, Is there a way to not add unnecessary functions (for me at least).
All interfaces inherit from IUnknown, unless you use corba interfaces:
{$INTERFACES CORBA}

Michael.

Reply by email

Michael Van Canneyt
to Zaher Dirkey
Zaher Dirkey wrote 8 lines
On Thu, Apr 15, 2010 at 11:09 AM, Michael Van Canneyt wrote: > {$INTERFACES CORBA} {$INTERFACES CORBA} It is resolved my problem, Is there any limit to use it (except it is not work in Delphi)?

Not that I know of :-)

Michael.

Reply by email

Marc Weustink
to Zaher Dirkey: On Thu, Apr 15, 2010 at 11:09 AM, Michael Van Canneyt {$INTERFACES CORBA} It is resolved…
Zaher Dirkey wrote 8 lines
On Thu, Apr 15, 2010 at 11:09 AM, Michael Van Canneyt wrote: > {$INTERFACES CORBA} {$INTERFACES CORBA} It is resolved my problem, Is there any limit to use it (except it is not work in Delphi)?
You cannot use casts like
var
   a: IMyObject;
   b: IMyOtherObject;
begin
   b := a as IMyOtherObject;

or functions like supports() (which uses queryinterface)

Marc

Reply by email

Graeme Geldenhuys
to Marc Weustink

Marc Weustink het geskryf:

Show quoted text 8 lines
You cannot use casts like var a: IMyObject; b: IMyOtherObject; begin b := a as IMyOtherObject; or functions like supports() (which uses queryinterface)

I remember reading something about this a year or two ago in the mailing list. As far as I remember, there was an alternative to do the same thing with CORBA-style interfaces, but for the life of me I can't remember what it was. I'll keeps searching to see if I can find the answers I am referring to.

While searching I did find one of my old message threads. And the answers to the questions I asked then, still elude me [4 years later]. :-(

http://lists.freepascal.org/lists/fpc-devel/2007-November/012060.html

@Michael van Canneyt
Maybe the Language Reference documentation could be extended to include such information? And maybe address the issues I mentioned the the message thread link I posted. Many developers seem to struggle with this, and the documentation seems the right place to address such info.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email

Michael Van Canneyt
to Graeme Geldenhuys
Graeme Geldenhuys wrote 27 lines
Marc Weustink het geskryf: > You cannot use casts like > var > a: IMyObject; > b: IMyOtherObject; > begin > b := a as IMyOtherObject; > > or functions like supports() (which uses queryinterface) I remember reading something about this a year or two ago in the mailing list. As far as I remember, there was an alternative to do the same thing with CORBA-style interfaces, but for the life of me I can't remember what it was. I'll keeps searching to see if I can find the answers I am referring to. While searching I did find one of my old message threads. And the answers to the questions I asked then, still elude me [4 years later]. :-( http://lists.freepascal.org/lists/fpc-devel/2007-November/012060.html @Michael van Canneyt Maybe the Language Reference documentation could be extended to include such information? And maybe address the issues I mentioned the the message thread link I posted. Many developers seem to struggle with this, and the documentation seems the right place to address such info.

You are right. I will have a look at the docus.

Michael.

Reply by email

Graeme Geldenhuys
to Marc Weustink: You cannot use casts like var a: IMyObject; b: IMyOtherObject; begin b := a as…

Marc Weustink het geskryf:

or functions like supports() (which uses queryinterface)

Actually, that *does* work with FPC 2.4.0. See attached console application.

I used supports() and a cast to get a Corba interface reference. It seems the compiler does some extra magic (probably with the GUID) to identify the interface via the Supports() call - without the need for QueryInterface.

begin
 ins := TAddCommand.Create;
 if Supports(ins, ICommand, cmd) then
 begin
   writeln('1. It worked');
   cmd.Execute;               // works
 end;
 cmd := nil;
 cmd := ins as ICommand;
 if Assigned(cmd) then
 begin
   writeln('2. It worked');
   cmd.Execute;                // works
 end;
 ins.Free;
end.

....and the the output generated...

1. It worked
TAddCommand.Execute
2. It worked
TAddCommand.Execute

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email

Graeme Geldenhuys
to Graeme Geldenhuys

Extending the example program a but further to test for not supported interfaces I found that the cast (via as syntax) to get a interface gives a compiler error [test 3 it program]. Using supports() still worked though [test 4 in program].

Cheers,
- Graeme -

Reply by email

Zaher Dirkey
to Marc Weustink: You cannot use casts like var a: IMyObject; b: IMyOtherObject; begin b := a as…
Marc Weustink wrote 20 lines
Zaher Dirkey wrote: > > On Thu, Apr 15, 2010 at 11:09 AM, Michael Van Canneyt > wrote: >> >> {$INTERFACES CORBA} > > {$INTERFACES CORBA} > > It is resolved my problem, Is there any limit to use it (except it is > not work in Delphi)? You cannot use casts like var  a: IMyObject;  b: IMyOtherObject; begin  b := a as IMyOtherObject; or functions like supports() (which uses queryinterface)

Can we have in the future something like IMyObject = interface(IObject) instead of use {$INTERFACES CORBA}

Zaher Dirkey

Reply by email