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

silvioprog silvioprog at gmail.com
Wed Feb 26 20:15:53 CET 2014


2014-02-26 13:28 GMT-03:00 Sven Barth <pascaldragon at googlemail.com>:

> Am 26.02.2014 16:11, schrieb silvioprog:
>
>  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)
>>
> This must be "class(specialize TThirdGeneric<T>)" (the "T" is the same
> type parameter as specified for the "TMyGeneric" declaration, so if it
> would be "TMyGeneric<MyType>" it would need to be "class(specialize
> TThirdGeneric<MyType>)")
>
>    public
>>     procedure ConfigureFoo;
>>   end;
>>
>>   { TMyClass }
>>
>>   TMyClass = class(TMyGeneric)
>>
> A class parent must always be a specialization as generics are no valid
> types per se. So here the correct declaration would again be
> "class(specialize TMyGeneric<WhateverTypeYouNeed>)".
>
>>   public
>>     procedure Post;
>>   end;
>>
> [snip]
>
>  Just trying to understand the generics concept correctly. :S
>>
>
> Regards,
> Sven


Compiled like a charm. I'm loving it. Very very nice!

So, I'll implement some methods in a descendant type of this class:

https://github.com/silvioprog/brookframework/blob/master/core/brookaction.pas#L262

then:

  TjTableEditAction = (eaList, eaCreate, eaUpdate, eaDelete);

  { TjTableEntityAction }

  generic TjTableEntityAction<T> = class(specialize TBrookEntityAction<T>)
  public
    { TODO: implement jTable paging -
http://www.jtable.org/apireference#genopt-paging }
    { TODO: implement jTable edit action -
http://www.jtable.org/apireference#Actions }
  end;

And generics will be very helpful in this task.

Thank you again Sven! (y)

ps. is there any complete documentation about generics in Free Pascal? The
Lazarus wiki is a bit incomplete.

-- 
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/2437138e/attachment.html>


More information about the fpc-pascal mailing list