delphigenericsdelphi-xe4

Can I have generic constrain of type procedure of object in Delphi


Can I have a 'Generic constrain' of type 'procedure of object' in 'Delphi'. I have given a piece of code to understand my issue.

var
  abc : procedure of object

  harry <T : abc > = class
  public
     procedure b (const handler : X);
  end;


procedure harry.b (const handler : X);
begin
  // do something
end;

Any help would be appreciable.


Solution

  • No, Delphi Generic constraints are not that flexible. The documentation is very clear on what you can use as a constraint:

    Constraints in Generics:

    Constraint items include:
    Zero, one, or multiple interface types
    Zero or one class type
    The reserved word "constructor", "class", or "record"

    A procedure of object does not satisfy any of those options.