View Issue Details

IDProjectCategoryView StatusLast Update
0004842FPCCompilerpublic2020-04-05 02:28
ReporterGory Bugs Department Assigned ToIvo Steinmann  
PrioritynormalSeveritymajorReproducibilityalways
Status assignedResolutionopen 
OSWIN32 
Summary0004842: implements keyword in properties
DescriptionSome Delphi functionality that is still missing.
Additional InformationReporter: marco (the gory bugs department)
EMail:
Tagscom
Fixed in Revision
FPCOldBugId2826
FPCTarget-
Attached Files

Relationships

related to 0008951 assignedIvo Steinmann FPC doesn't allow implements properties be of class types 
related to 0015209 closedFlorian Interface using Implements gives crash 
related to 0018058 resolvedSergei Gorelkin "overriding" and delegated Implementation in interfaces dont work. 

Activities

2003-12-02 12:00

 

code.pp (878 bytes)   
{$mode Delphi}

Uses Classes;

type

  IJclScheduleDayFrequency = interface(IUnknown)
    ['{6CF37F0D-56F4-4AE6-BBCA-7B9DFE60F50D}']
    function GetStartTime: Cardinal;
    procedure SetStartTime(Value: Cardinal);
    property StartTime: Cardinal read GetStartTime write SetStartTime;
  end;

  TDailyFreq = class
  public
    function GetStartTime: Cardinal;
    procedure SetStartTime(Value: Cardinal);
  end;

//  IScheduleDayFrequency

  TSchedule = class(TInterfacedObject)
    FDailyFreq:TDailyFreq;
  protected
    property DailyFreq: TDailyFreq read FDailyFreq implements IJclScheduleDayFrequency;
  end;


function TDailyFreq.GetStartTime:CARDINAL;
begin
 exit(0);
end;

procedure TDailyFreq.SetStartTime(value:Cardinal);
begin
end;


begin
end.
code.pp (878 bytes)   

Jonas Maebe

2006-07-12 15:30

manager   ~0008412

Christian Iverson committed something for this in trunk on 2006-07-11

Christian Iversen

2006-09-23 01:58

developer   ~0009048

Basic functionality for the Implements keyword has been added, and works without problems.

However, using a function as the read-field of the property is not yet supported.

2009-12-23 19:36

 

tw4842.pp (832 bytes)   
{ $mode Delphi}

Uses Classes;

type

  IJclScheduleDayFrequency = interface(IUnknown)
    ['{6CF37F0D-56F4-4AE6-BBCA-7B9DFE60F50D}']
    function GetStartTime: Cardinal;
    procedure SetStartTime(Value: Cardinal);
    property StartTime: Cardinal read GetStartTime write SetStartTime;
  end;

  TDailyFreq = class
  public
    function GetStartTime: Cardinal;
    procedure SetStartTime(Value: Cardinal);
  end;

//  IScheduleDayFrequency

  TSchedule = class(TInterfacedObject,IJclScheduleDayFrequency)
    FDailyFreq:TDailyFreq;
  protected
    property DailyFreq: TDailyFreq read FDailyFreq implements IJclScheduleDayFrequency;
  end;


function TDailyFreq.GetStartTime:CARDINAL;
begin
 result:=0;
 exit;
end;

procedure TDailyFreq.SetStartTime(value:Cardinal);
begin
end;


begin
end.
tw4842.pp (832 bytes)   

Florian

2009-12-23 19:37

administrator   ~0033286

Fixed test code.

Sergei Gorelkin

2009-12-25 12:34

developer   ~0033309

I finally seem to realize where the gotcha is.

Delphi does not require that the delegate class implements the target interface itself. Moreover, an interface can get 'split' between delegate and container classes: in the attached example, IJclScheduleDayFrequency.QueryInterface, AddRef and Release methods are implemented in TSchedule, and GetStartTime and SetStartTime are implemented in TDailyFreq.
I attached a more explicit example for this: tw4842a.pp.

So it appears that my patch to 0015209 was somewhat incorrect in this respect: it makes delegation to class property working, but assuming that the delegate class *does* implement the target interface. Anyway, it may viewed as a nice-to-have feature.

2009-12-25 12:35

 

tw4842a.pp (692 bytes)

Bi0T1N

2020-04-05 02:28

reporter   ~0121913

Last edited: 2020-04-05 02:28

View 2 revisions

Trying to compile any of the above examples fails.

Example info for tw4842a.pp (FPC 3.2.0rc1 and 3.3.1-r44326):
tw4842a.pp(20,71) Error: Class "TDelegate" does not implement interface "IDescendant"
tw4842a.pp(21,3) Error: Compilation raised exception internally
Fatal: Compilation aborted
An unhandled exception occurred at $0000000100073C90:
EAccessViolation: Access violation
  $0000000100073C90
  $000000010017D161
  $000000010017FD6A
  $0000000100180AA7
  $0000000100194039
  $000000010017318C
  $0000000100173F3B
  $00000001000F1392
  $00000001000ECBEF
  $00000001000F04ED
  $00000001001BB4DC
  $000000010003F881
  $0000000100017FE1
  $0000000100001A5D
  $0000000100001A76
  $0000000100014870
  $0000000100001840


Changing TDelegateTest=class(TObject) to TDelegateTest=class(TObject,IDescendant) gives
test.pas(13,17) Error: No matching implementation for interface method "QueryInterface(constref TGuid;out <Formal type>):LongInt; StdCall;" found
test.pas(13,17) Error: No matching implementation for interface method "_AddRef:LongInt; StdCall;" found
test.pas(13,17) Error: No matching implementation for interface method "_Release:LongInt; StdCall;" found
test.pas(13,17) Error: No matching implementation for interface method "AncestorMethod;" found


Issue History

Date Modified Username Field Change
2006-06-11 14:32 Peter Vreman Status new => confirmed
2006-07-12 15:30 Jonas Maebe Note Added: 0008412
2006-07-12 15:30 Jonas Maebe Reporter FPC core team => Gory Bugs Department
2006-07-12 15:30 Jonas Maebe Product Version 1.9.1 =>
2006-07-12 15:30 Jonas Maebe Additional Information Updated
2006-07-12 19:29 Florian Status confirmed => assigned
2006-07-12 19:29 Florian Assigned To => Christian Iversen
2006-09-23 01:58 Christian Iversen Note Added: 0009048
2006-09-23 01:58 Christian Iversen Status assigned => confirmed
2007-01-06 11:28 Christian Iversen FPCTarget => -
2007-01-06 11:28 Christian Iversen Status confirmed => assigned
2007-10-28 14:01 Marco van de Voort Relationship added related to 0008951
2009-10-16 23:39 Marco van de Voort Tag Attached: com
2009-12-11 16:05 Jonas Maebe Relationship added related to 0015209
2009-12-23 19:36 Florian File Added: tw4842.pp
2009-12-23 19:37 Florian Note Added: 0033286
2009-12-25 12:34 Sergei Gorelkin Note Added: 0033309
2009-12-25 12:35 Sergei Gorelkin File Added: tw4842a.pp
2010-03-27 16:20 Ivo Steinmann Assigned To Christian Iversen => Ivo Steinmann
2010-11-26 15:51 Jonas Maebe Relationship added related to 0018058
2020-04-05 02:28 Bi0T1N Note Added: 0121913
2020-04-05 02:28 Bi0T1N Note Edited: 0121913 View Revisions