[fpc-pascal] [PATCH] Addition of OnNotify event on "TFPGObjectList" and "TFPGList" triggered on the insert, delete and extract methods.

denisgolovan denisgolovan at yandex.ru
Sat Feb 20 16:06:52 CET 2016


20.02.2016, 02:05, "Sven Barth" <pascaldragon at googlemail.com>:
> There's no need for a sample. This degradation is the whole reason why the non-generic classes TFPObjectList and TFPList exist compared to TObjectList and TList which do have notifications.
>
> Regards,
> Sven

/ My previous mail appeared to be in html format. Sorry for that.

Hi

That always keeps me wondering - why neither FPC, no any other mainstream static-type language implements specialization based not only on types, but on compile-time constants as well?

I mean something like

  TGenericList<T,options> = class
    ...
  end;

procedure TGenericList<T,options>.Delete(index:integer);
begin
  if (nnNotifyDelete in options) and Assigned(FOnDelete) then
    FOnDelete(...);
  end;
end;

// usage
type
  TMyList = specialize TGenericList<integer, [nnNotifyAdd, nnNotifyDelete, nnNotifyChange]>;

... that "if (nnNotifyDelete in options) " condition will optimized out by compiler if options lack corresponding enum constant.
Of course, FOnDelete property should be omitted as well in ideal case. That might require something like "static if" in D.

I've done that trick for ages using m4 preprocessor and it works really good, why it's still not supported natively by compilers themselves?

-- 
Regards,
Denis Golovan



More information about the fpc-pascal mailing list