View Issue Details

IDProjectCategoryView StatusLast Update
0038238FPCCompilerpublic2020-12-24 14:45
ReporterJeppe Johansen Assigned ToSven Barth  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version3.3.1 
Fixed in Version3.3.1 
Summary0038238: Pointers to record methods don't seem to work
DescriptionTrying to assign a pointer to a record method to any variable or argument that takes a procedure/function of object results in a compiler error

Example testcase attached
TagsNo tags attached.
Fixed in Revision47826
FPCOldBugId
FPCTarget-
Attached Files

Relationships

has duplicate 0031528 resolvedSven Barth pointer to advanced record methods 

Activities

Jeppe Johansen

2020-12-20 16:17

developer  

testcase.pas (923 bytes)   
program testcase;

{$mode objfpc}
{$modeswitch advancedrecords}

type
  TCallback = procedure(AValue: longint) of object;

  TRec = record
    Clb: TCallback;
    procedure AddCallback(ACallback: TCallback);
    procedure TriggerCallback(AValue: longint);
  end;

  TRec2 = record
    Value: longint;
    Rec: TRec;
    procedure CLB(AValue: longint);
    procedure InitStuff;
  end;

procedure TRec.AddCallback(ACallback: TCallback);
begin
  Clb:=ACallback;
end;

procedure TRec.TriggerCallback(AValue: longint);
begin
  if assigned(Clb) then
    Clb(AValue);
end;

procedure TRec2.CLB(AValue: longint);
begin
  Value:=AValue;
end;

procedure TRec2.InitStuff;
begin
  Rec.AddCallback(@CLB);
end;

var
  Rec1, Rec2: TRec2;
begin
  Rec1.InitStuff;
  Rec2.InitStuff;

  Rec1.Rec.TriggerCallback(1234);
  Rec2.Rec.TriggerCallback($0943);

  if Rec1.Value<>1234 then
    Halt(1);
  if Rec2.Value<>$0943 then
    Halt(2);
end.

testcase.pas (923 bytes)   

Serge Anvarov

2020-12-20 17:42

reporter   ~0127724

It looks like "of object" only accepts a class or object, but not a record: with "TRec2 = class..." or "TRec2 = object..." no compilation error.
This is not compatible with Delphi.

jamie philbrook

2020-12-20 19:24

reporter   ~0127731

Rightfully so.

CLB does not look like an object procedure to me ?

although the two do have a background SELF to them I don't see how the compiler will allow this because they may not be managed the same way?

Procedure of Object is not the same as a procedure and most likely those sitting in a record may not be handled the same way for the SELF parameter to point to the heap.

jamie philbrook

2020-12-20 19:42

reporter   ~0127733

Last edited: 2020-12-20 19:49

View 2 revisions

procedure TRec2.InitStuff;
begin
  Rec.AddCallback(Rec.CLB); <<<<<
end;

I see no way how Delphi could of accepted that without that correction
I can't even say if that will actually work but it compiles for you.

That was just to show if you get the types matched it does compile! The rest well?

Sven Barth

2020-12-20 23:43

manager   ~0127738

Considering that I learned in preparation of r47794 that, yes, Delphi does allow such code (and also compiles the posted testcase with adjustments for Delphi syntax), I've fixed the location that was missed in that revision now as well.

Please test and close if okay.

Benito van der Zander

2020-12-21 23:49

reporter   ~0127753

Reminds me of 0031528

Jeppe Johansen

2020-12-24 14:45

developer   ~0127789

Seems to work nicely. Thanks

Issue History

Date Modified Username Field Change
2020-12-20 16:17 Jeppe Johansen New Issue
2020-12-20 16:17 Jeppe Johansen File Added: testcase.pas
2020-12-20 17:42 Serge Anvarov Note Added: 0127724
2020-12-20 19:24 jamie philbrook Note Added: 0127731
2020-12-20 19:42 jamie philbrook Note Added: 0127733
2020-12-20 19:49 jamie philbrook Note Edited: 0127733 View Revisions
2020-12-20 23:09 Sven Barth Assigned To => Sven Barth
2020-12-20 23:09 Sven Barth Status new => assigned
2020-12-20 23:43 Sven Barth Status assigned => resolved
2020-12-20 23:43 Sven Barth Resolution open => fixed
2020-12-20 23:43 Sven Barth Fixed in Version => 3.3.1
2020-12-20 23:43 Sven Barth Fixed in Revision => 47826
2020-12-20 23:43 Sven Barth FPCTarget => -
2020-12-20 23:43 Sven Barth Note Added: 0127738
2020-12-21 23:49 Benito van der Zander Note Added: 0127753
2020-12-22 13:51 Sven Barth Relationship added has duplicate 0031528
2020-12-24 14:45 Jeppe Johansen Status resolved => closed
2020-12-24 14:45 Jeppe Johansen Note Added: 0127789