[fpc-pascal] How to add new methods in a existent generic type?

silvioprog silvioprog at gmail.com
Wed Feb 26 16:11:40 CET 2014


Hello,

I'm trying to add new features in a third generic type. Please see this
simulation below:

  { TThirdGeneric }

  generic TThirdGeneric<T> = class
  private
    FFoo: T;
  public
    procedure Post;
    property Foo: T read FFoo;
  end;

  { TMyGeneric }

  generic TMyGeneric<T> = class(TThirdGeneric)
  public
    procedure ConfigureFoo;
  end;

  { TMyClass }

  TMyClass = class(TMyGeneric)
  public
    procedure Post;
  end;

...

{ TMyGeneric }

procedure TMyGeneric.ConfigureFoo;
begin
  ... pre configure Foo ...
end;

{ TMyClass }

procedure TMyClass.Post;
begin
  Write(Foo.AProperty); // using pre configured Foo
end;

Just trying to understand the generics concept correctly. :S

-- 
Silvio Clécio
My public projects - github.com/silvioprog
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20140226/942edf32/attachment.html>


More information about the fpc-pascal mailing list