[fpc-devel] Creating Generic Object

Sven Barth pascaldragon at googlemail.com
Mon Apr 16 07:53:11 CEST 2018


Amir <Amir at aavani.net> schrieb am So., 15. Apr. 2018, 23:51:

> Hi all,
>
>    Currently, FPC allows declaring objects as
> var
>    MyMap: specialize TFPGMap<AnsiString, MyData>;
>
> This is very nice feature since I do not need define every Map/List/etc
> as a  separate type.
>
> But to create MyMap object, one has to write something like:
>    MyMap := (specialize TFPGMap<AnsiString, MyData>).Create()
>
> Wondering if there is any shorter way to handle the objects'
> initialization, .e.g., something like
>    MyMap := auto.Create;
>

Just declare a type for the specialization:

=== code begin ===

type
  TMyDataMap = specialize TFPGMap<AnsiString, MyData>;

var
  MyData: TMyDataMap;
begin
  MyData := TMyDataMap.Create;
end.

=== code end ===

Regards,
Sven

>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20180416/4695493a/attachment.html>


More information about the fpc-devel mailing list