[fpc-pascal] A better way?

Sven Barth pascaldragon at googlemail.com
Fri Apr 15 10:56:26 CEST 2016


Am 15.04.2016 08:46 schrieb "Ryan Joseph" <ryan at thealchemistguild.com>:
> Does this look like more work than using $includes? Maybe I need to
seriously considering reorganizing my projects to work like this but it
just feels wrong for some reason.
>
> =====================
>
> unit Globals;
> interface
>
> type
>         HClassB = 'TClassB';    // declare a hint to the class name
>
> implementation
> end.
>
> =====================
>
> unit ClassB;
> interface
> uses
>         ClassA;
>
> type
>         TClassB = class
>                 procedure DoSomething (sender: TClassA);
>         end;
>
> implementation
>
> procedure TClassB.DoSomething (sender: TClassA);
> begin
>         // full access to TClassA
> end;
>
> end.
>
> =====================
>
> unit ClassA;
> interface
> uses
>         Globals;
>
> type
>         TClassA = class
>                 // The interface section can't know about TClassB so we
declare a
>                 // class name hint from Globals.pas (HClassB) and assign
the paramter with it
>                 // using the "hint" syntax
>                 procedure SetValue (value: TObject[HClassB]);
>         end;
>
> implementation
>
> // use ClassB now so hints evaluate
> uses
>         ClassB;
>
> procedure TClassA.SetValue (value: TObject[HClassB]);
> begin
>         // behind the scenes the compiler (or preparser if FPC has one)
replaces the text "TObject[HClassB]" to “TClassB" or throws an error if the
identifier TClassB is not found
>         value.DoSomething(self);
> end;
>
> end.

*shudders* Before we introduce such syntax I'd prefer to get the formal
class types that were added for Objective Pascal working with Object Pascal
as well (which would be exactly what you want just with a more sane syntax).

But again: you're currently fighting against the language. Use interfaces
and abstract classes and overthink your dependencies and design.

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


More information about the fpc-pascal mailing list