Let me also share the results of tests for method pointers with different 
default values. The example is a bit convoluted, but it shows all possible 
combinations. It turns out that any component event definition always overrides 
the default values ​​from the class.
 
program Project1;
type
  TTest = class
    procedure test(a: string; b: string = 'class');
  end;
  TReq = procedure (a, b: string) of object;
  TOpt = procedure (a: string = 'def1'; b: string = 'def2') of object;
 
procedure TTest.test(a: string; b: string);
begin
  writeln(a, ', ', b);
end;
 
var
  lReq: TReq;
  lOpt: TOpt;
  lTest: TTest;
begin
  lTest := TTest.Create;
  lReq := @lTest.test;
  lOpt := @lTest.test;
 
  lReq('req1', 'req2');
  lOpt;
  TOpt(lReq);
  TReq(lOpt)('opt1', 'opt2');
end.
 
 
  
>Среда, 23 октября 2024, 2:28 +05:00 от Martin Frb via fpc-devel 
><fpc-devel@lists.freepascal.org>:
> 
>Is the below meant to be allowed?
>It compiles, it also compiles if you have no default in the base, but a
>default in the sub class.
>
>type
>   TFoo = class
>     procedure Bar (const Item: String; AnObject: TObject = nil); virtual;
>   end;
>   TFoo2 = class(TFoo)
>     procedure Bar (const Item: String; AnObject: TObject); override;
>   end;
>
>
>It even works with both having a diff default.
>
>   TFoo = class
>     procedure Bar (const Item: String; AnObject: integer = 1); virtual;
>   end;
>   TFoo2 = class(TFoo)
>     procedure Bar (const Item: String; AnObject: integer=2); override;
>   end;
>
>_______________________________________________
>fpc-devel maillist -  fpc-devel@lists.freepascal.org
>https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
 
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to