In the department of wishful thinking:

In the department of wishful thinking:

type

TElement = class(TSomeClass)

Sibling: TElement;

end;

type

LinkAttribute = class(TCustomAttribute)

FLink: TElement;

constructor Create(aLink:TElement);

end;

TContainer = class

X1: TElement;

[Link(X1)] //<– wish I could use an attribute to link X1 with Y1

Y1: TElement;

X2: TElement;

[Link(X2)] //<– wish I could use an attribute to link X2 with Y2

Y2: TElement;

end;

It would be nice if attributes could reference class/record local fields or properties.

I know – it would put a lot of load on the compiler / linker.

If the compiler was two pass, order would not be important.

Since the compiler is single pass – perhaps something like

TContainer = class

[Link(forward Y1)]

X1: TElement;

Y1: TElement;

[Link(forward Y2)]

X2: TElement;

Y2: TElement;

end;

could be an option as well.

#MoreDeclarationLessCode

7 thoughts on “In the department of wishful thinking:


  1. Asbjørn Heid


    – Binding related time/value series for SQL queries.


    – Linking controls with value fields


    – Associate a handler with an event


    Basically, it would be like visual live binding with compile time validation instead of runtime validation.

    Like


  2. Lars Fosdal I don’t see how your proposal would work. It seems what you really want to do is to have


    type


    PPElement = ^TElement;


    LinkAttribute = class(TCustomAttribute)


    FLink: PPElement;


    constructor Create(aLink:PPElement);


    end;




    X1: TElement;


    [Link(@X1)]


    Y1: TElement;


    otherwise how do you envision this working?

    Like


  3. Asbjørn Heid – Yes, that is basically what I want. In an instance of a class – any reference is relative to the base instance. Hence the compiler magic needs to inject the correct reference wrapper code for access (self + offset / self VMT resolve). I am not saying it would be trivial, but it sure would be nice.

    Like


  4. Lars Fosdal Sounds quite complicated to implement. Couldn’t you settle for having NameOf implemented? Then you can access the member at runtime through RTTI?


    So it would be


    [Link(NameOf(X1))]


    Y1: TElement;


    Then you could write some helpers to extract the value of the link element attribute at runtime, given an object instance.

    Like

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.