Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2018-04

Creating Generic Object

4 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Amir

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;

Thanks,
Amir

Reply by email

Sven Barth
to Amir

Amir schrieb am So., 15. Apr. 2018, 23:51:

Show quoted text 16 lines
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

Reply by email

Bart
to Sven Barth
Sven Barth wrote
> This is very nice feature since I do not need define every Map/List/etc > as a separate type. Just declare a type for the specialization:

The obvious (and correct answer) but, this is exactly what OP tries to avoid (if I understand OP correctly).

Bart

Reply by email

Sven Barth
to Bart

Bart schrieb am Mo., 16. Apr. 2018, 12:18:

Show quoted text 11 lines
On Mon, Apr 16, 2018 at 7:53 AM, Sven Barth via fpc-devel wrote: >> This is very nice feature since I do not need define every Map/List/etc >> as a separate type. > Just declare a type for the specialization: The obvious (and correct answer) but, this is exactly what OP tries to avoid (if I understand OP correctly).

But the OP can't avoid it, simple as that.

Regards,
Sven

Reply by email