[fpc-pascal] Question on type helpers

Sven Barth pascaldragon at googlemail.com
Sat Dec 31 19:22:45 CET 2016


Am 31.12.2016 16:28 schrieb "Bart" <bartjunk64 at gmail.com>:
>
> Hi,
>
> Why is it that type helpers must be declared in the Interface section
> of a unit and cannot be private in Implementation section?
>
> Consider this (useless) example:
>
> unit thtest;
>
> {$mode objfpc}{$H+}
> {$modeswitch typehelpers}
>
> interface
>
> type
>   TSomeType = record end;
>   TA = Array of TSomeType;
>
>   { TAHelper }
>
>   TAHelper = type helper for TA
>     constructor Create(A: TA);
>     procedure DoIt;
>   end;
>
> procedure X;
>
> implementation
>
> procedure X;
> var
>   A: TA;
> begin
>   A.DoIt;
> end;
>
> { TAHelper }
>
> constructor TAHelper.Create(A: TA);
> begin
>   Self := A;
> end;
>
> procedure TAHelper.DoIt;
> begin
>   ;
> end;
>
> end.
>
> This compiles fine.
> But when you move the declaration of TAHelper to the implementation
> section, then you get a compiler error:
>
> thtest.pp(21,5) Fatal: Syntax error, "CREATE" expected but "DOIT" found
> Line 21 is
>   A.DoIt;
>
> I'm using fpc 3.0.0 (32-bit) on Windows.

You did put the helper declaration before the implementation of X, right?

If you still have a problem, please open a bug report with an example
(cause that should definitely work).

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20161231/25a49dca/attachment.html>


More information about the fpc-pascal mailing list