Re: [fpc-devel] Interface usage causes FPC to crash

2012-11-30 Thread David Ballesteros
Hi,

Im interested on known the answers to Graeme  questions.

Cheers
David
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] Interface usage causes FPC to crash

2012-11-30 Thread Sergei Gorelkin

30.11.2012 17:20, David Ballesteros пишет:

Hi,

Im interested on known the answers to Graeme  questions.


Delegation to interface-type properties is fully supported.
Delegation to class-type properties is supported, but it requires the delegate class to implement 
the interface (this requirement is absent in Delphi).


Method resolution also works, but it is mutually exclusive with delegation.

The crash at compilation of course needs to be fixed.

Regards,
Sergei
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


[fpc-devel] Interface usage causes FPC to crash

2012-11-28 Thread Graeme Geldenhuys
Hi,

I tested the attached program under Delphi 7 and FPC 2.6.0 and FPC 2.7.1
(dated 2012-11-15).

The test application tests two things:
  1) Interface delegation via another class
  2) Overriding a interface implementation using method resolution


Under Delphi 7 the test application compiles and runs as expected.

Under FPC (both 2.6.0 and 2.7.1)
 - I get a compiler error. I thought interface delegation was
   supported in FPC?
 - I also get a compiler crash with an AV - in both versions.



Isn't interface delegation supported in FPC?

Is method resolution supported in FPC?

Why does the compiler crash while compiling?



8-8-8-8-8
Free Pascal Compiler version 2.6.0 [2011/12/23] for x86_64
Copyright (c) 1993-2011 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling test.pas
test.pas(38,76) Error: Class TMyIntfClass does not implement interface
IMyIntf
Fatal: Compilation aborted
An unhandled exception occurred at $0054CA3D :
EAccessViolation : Access violation
  $0054CA3D
  $00532148
  $0056CEF4
  $0042392F
8-8-8-8-8



The expected output when running the test application should be:

--
c:\Programming\test\interface_delegation_2test
TMyIntfClass.P1
TMainForm.MyP2

--


Regards,
  - Graeme -

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

program test;

{$ifdef FPC}
  {$mode objfpc}{$H+}
{$else}
  {$APPTYPE CONSOLE}
{$endif}

uses
  Classes;

//--  Interface  --

type

  IMyIntf = interface(IInterface)
  ['{ED858BD2-0E49-4B42-861D-6F415A7C0CF0}']
procedure P1;
procedure P2;
  end;


  { Delegation class.
NOTE: Documenatation suggested we use the TAggregatedObject, but
  under Delphi 7 (at least) we can use TObject too. }
  TMyIntfClass = class(TObject)
  private
{ IMyIntf implementation }
procedure P1;
procedure P2;
  end;


  TMainForm = class(TComponent, IMyIntf)
  private
FMyIntfClass: TMyIntfClass;
{ delegate IMyIntf implementation to another class }
property MyIntfClass: TMyIntfClass read FMyIntfClass implements IMyIntf;
  public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Run;
{ overrides the IMyIntf.P2 implementation using name resolution }
procedure IMyIntf.P2 = MyP2;  
procedure MyP2;
  end;



//--  Implementation  --


procedure TMyIntfClass.P1;
begin
  Writeln(Classname + '.P1');
end;

procedure TMyIntfClass.P2;
begin
  Writeln(Classname + '.P2');
end;



constructor TMainForm.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FMyIntfClass := TMyIntfClass.Create;
end;

destructor TMainForm.Destroy;
begin
  FMyIntfClass.Free;
  inherited Destroy;
end;

procedure TMainForm.Run;
begin
  (self as IMyIntf).P1;
  (self as IMyIntf).P2;
end;

procedure TMainForm.MyP2;
begin
  Writeln(Classname + '.MyP2');
end;



// - Application starting point  -
var
  frm: TMainForm;
begin
  frm := TMainForm.Create(nil);
  try
frm.Run;
  finally
frm.Free;
  end;
end.
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel