Sign in Join

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

Mailing lists / fpc-pascal / 2017-11

using Interfaces in descendant classes 2.6.4 vs 3.x

4 messages · 1 person · –

Reply by email Subscribe to this list Your subscription

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

Graeme Geldenhuys

Hi,

Some of my programs were last compiled with FPC 2.6.4, and there I used Corba-style Interfaces without a problem. I've now recompiled those projects with FPC 3.0.4 and the program immediately crashes.

Debugging I found that I was trying to use a interface reference, but forgot to check if it was nil or not. I've fixed the code, but the issue is still not resolved. The class in question DOES implement the interface, but FPC 3.x always returns nil, whereas FPC 2.6.4 correctly returns a Interface reference.

The class hierarchy is as follows...

      TBaseApplication = class(TObject, ICmdLineParams);
            |
      TX11Application = class(TBaseApplication)
            |
      TfpgApplication = class(TX11Application)

In my applications I only work with a TfpgApplication instance. If the interface is fully implemented in TBaseApplication, why does FPC 3.x _always_ report that TfpgApplication doesn't support the ICmdLineParams?

My code looks as follows:

var
   cmd: ICmdLineParams;
begin
   if Supports(fpgApplication, ICmdLineParams, cmd) then
   begin
     if cmd.HasOption('n', 'newinstance') then
       MainProc
     else if not AnotherInstance then
       MainProc;
   end
   else
   begin
      // ICmdLineParams interface is not supported
   end;

I looked at the wiki and the FPC 3.x "User Changes" pages and the only reference to Interface changes is this.

http://wiki.freepascal.org/User_Changes_3.0.0#Classes_implementing_forward-declared_interfaces

The wiki is very vague with what it means. Either way, I don't consider my code wrong. I'm using a class hierarchy and the base class does implement the Interface in question fully, so why does FPC 3.x think it doesn't? Bottom line, is this a FPC bug and how to I change my code to work until the bug can be fixed?

Regards,
Graeme

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp

Reply by email

Graeme Geldenhuys
to Graeme Geldenhuys
Graeme Geldenhuys wrote 5 lines
I looked at the wiki and the FPC 3.x "User Changes" pages and the only reference to Interface changes is this. http://wiki.freepascal.org/User_Changes_3.0.0#Classes_implementing_forward-declared_interfaces

Please note that I'm not using Interface Forward Declarations in my code. The interface definition is fully defined in a separate unit, and that unit is referenced in the uses clause (interface section of the unit) where TBaseApplication is defined.

So I highly doubt my issue is related to the above URL's topic.

Regards,
Graeme

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp

Reply by email

Graeme Geldenhuys
to Graeme Geldenhuys: Some of my programs were last compiled with FPC 2.6.4, and there I used Corba-style…

Attached is a sample application reproducing the problem. Compile the program with FPC 2.6.4 and everything works. Compile it with FPC 3.x and no interface reference is ever returned.

Sample output:

=======[ compiled with FPC 3.0.0, 3.0.2, 3.0.4 and 3.1.1]============ [tmp]$ ./project1
TClassA: ICmdLine interface is not supported!
TClassB: ICmdLine interface is not supported!
TClassC: ICmdLine interface is not supported!

=======[ compiled with FPC 2.6.4]============
[tmp]$ ./project1
TCmdLineImpl: ICmdLine.MyProc implementation
TCmdLineImpl: ICmdLine.MyProc implementation
TCmdLineImpl: ICmdLine.MyProc implementation

I did some further testing. In the attached project I have a dedicated class that implements the interface, then another class that implements the interface using interface delegation. If I change the sample code and NOT use interface delegation, but let TClassA directly implement the ICmdLine interface, then everything works.

But developers shouldn't need to be forced to do this. FPC support interface delegation and the real interface is a lot more complex to implement than the very simplified attached example. The nail in the coffin is that it used to work in FPC 2.6.4, but is now broken in FPC 3.x

Regards,
Graeme

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp

Reply by email

Graeme Geldenhuys
to Graeme Geldenhuys
Graeme Geldenhuys wrote
Attached is a sample application reproducing the problem. Compile the program with FPC 2.6.4 and everything works. Compile it with FPC 3.x and no interface reference is ever returned.

Yet more testing..... Now I've managed to get it to work in all FPC versions. Yeah!!!

If I change my class that does interface delegation to the following syntax:

    TClassA = class(TObject, ICmdLine)
    private
     FCmdLineParams: TCmdLineImpl;
     function GetCmdLineParamsInterface: TCmdLineImpl;
     property ChildDelegate: TCmdLineImpl read GetCmdLineParamsInterface
implements ICmdLine;
    public
      destructor Destroy; override;
    end;

Then it works. Note I changed the function and property definitions.

Still strange that FPC 2.6.4 worked in my prior example and FPC 3.x not. I also didn't see any "User Changes" on the wiki about this changed behaviour of Interface Delegation.

Regards,
Graeme

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp

Reply by email