Sign in Join

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

Mailing lists / pas2js / 2022-02

How I do it?

4 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

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

Henrique Gottardi Werlang

I'm having a question of how to declare some generic functions in FPC.

At Delphi I declare them like this:

type
  TProc = reference to procedure;
  TProc<T> = reference to procedure (Arg: T);
  TProc<T1, T2> = reference to procedure (Arg1: T1; Arg2: T2);

How do I make an equivalent statement in FPC?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/pas2js/attachments/20220211/1ac27e8a/attachment.htm>

Reply by email

Michael Van Canneyt
to Henrique Gottardi Werlang
Henrique Gottardi Werlang wrote 10 lines
I'm having a question of how to declare some generic functions in FPC. At Delphi I declare them like this: type TProc = reference to procedure; TProc<T> = reference to procedure (Arg: T); TProc<T1, T2> = reference to procedure (Arg1: T1; Arg2: T2); How do I make an equivalent statement in FPC?

You can't, currently, in ObjFPC mode.

We're coordinating with the FPC compiler team.
They forbid it to allow omitting the <t> in method implementations.

As far as I understood, it should work in Delphi mode; but I didn't check that.

Michael.

Reply by email

Mattias Gaertner
to Michael Van Canneyt
Show quoted text 15 lines
On Fri, 11 Feb 2022, Henrique Gottardi Werlang wrote: > I'm having a question of how to declare some generic functions in > FPC. > > At Delphi I declare them like this: > > type > TProc = reference to procedure; > TProc<T> = reference to procedure (Arg: T); > TProc<T1, T2> = reference to procedure (Arg1: T1; Arg2: T2); > > How do I make an equivalent statement in FPC? You can't, currently, in ObjFPC mode.

Currently you must put them in a unit with mode delphi. You can specialize them in both modes.

Show quoted text 5 lines
We're coordinating with the FPC compiler team. They forbid it to allow omitting the <t> in method implementations. As far as I understood, it should work in Delphi mode; but I didn't check that.

Yes, they work in main, but are not yet well tested.

Mattias

Reply by email

Sven Barth
to Michael Van Canneyt: You can't, currently, in ObjFPC mode. We're coordinating with the FPC compiler team. They…
Michael Van Canneyt wrote 19 lines
On Fri, 11 Feb 2022, Henrique Gottardi Werlang wrote: > I'm having a question of how to declare some generic functions in FPC. > > At Delphi I declare them like this: > > type >  TProc = reference to procedure; >  TProc<T> = reference to procedure (Arg: T); >  TProc<T1, T2> = reference to procedure (Arg1: T1; Arg2: T2); > > How do I make an equivalent statement in FPC? You can't, currently, in ObjFPC mode. We're coordinating with the FPC compiler team. They forbid it to allow omitting the <t> in method implementations.

To be slightly more accurate: it was forbidden, because it wasn't known at the time that it would be possible - FPC generics came before Delphi ones.

Regards,
Sven

Reply by email