Sign in Join

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

Mailing lists / fpc-pascal / 2022-08

Class or Record Helper for Interface?

6 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

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

Anthony Walter

I just tried to write a type / record /class helper for an interface type and the compiler deosn't seem to allow it. Is this allowed and what is the syntax?

Also, are multiple type helpers allowed or were they removed? If they are allowed what is the directive?

Marco van de Voort
to Anthony Walter

Op 8/27/2022 om 3:06 PM schreef Anthony Walter via fpc-pascal:

Ah, it seems the problem is even in {$mode delphi} you must use {$modeswitch typehelpers} to define a type helper for an interface.

I put a note on the checklist for the next major version about this to review this. (only review, not a guarantee that it will change. But at least it won't go through unnoticed then)

Sven Barth
to Anthony Walter: Ah, it seems the problem is even in {$mode delphi} you must use {$modeswitch typehelpers}…

Anthony Walter via fpc-pascal schrieb am
Sa., 27. Aug. 2022, 15:07:

Ah, it seems the problem is even in {$mode delphi} you must use {$modeswitch typehelpers} to define a type helper for an interface.

Delphi doesn't support interface helpers, so I don't know whether they'd use "class helper", "record helper" or even "interface helper". Thus it's only supported with type helpers which are generally available in mode Delphi with the typehelpers modeswitch.

Regards,
Sven

Anthony Walter
to Sven Barth

I'd be all for just eliminating the "class", "record", and "type" helper and adding support for just using "helper" in all modes.

type
  TPointHelper = helper for TPoint
  end;
  TCanvasHelper = helper for TCanvas
  end;
  TDoubleHelper = helper for Double
  end;
  TInterfaceHelper = helper for IInterface
  end;

I know this would make code written this way incompatible with Delphi, but I think pretending the helper type serves no actual purpose. The only thing it does is it makes it harder for developers to remember which names to use in which cases. The compiler should be able to figure it out.

Sven Barth
to Anthony Walter

Anthony Walter schrieb am Sa., 27. Aug. 2022, 22:45:

I'd be all for just eliminating the "class", "record", and "type" helper and adding support for just using "helper" in all modes.

"type helper" already allows you to use any supported type. There won't be any further changes regarding this.

Regards,
Sven