Einzelnen Beitrag anzeigen

Benutzerbild von Neutral General
Neutral General

Registriert seit: 16. Jan 2004
Ort: Bendorf
5.219 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#1

Anonyme Methoden in Attributen

  Alt 11. Feb 2015, 14:05
Delphi-Version: XE7
Hallo,

Das scheint leider nicht zu gehen:
Delphi-Quellcode:
TAnonym = reference to procedure;

TMyCustomAttribute = class(TCustomAttribute)
  constructor Create(Anonym: TAnonym); // compiliert
end;

// Funktioniert nicht: "Konstantenausdruck erwartet"
[TMyCustomAttribute(
  procedure
  begin
    ShowMessage('Test');
  end)
]
TTestclass = class

end;
Das finde ich schade und ich wäre froh wenn Embarcadero sowas implementieren könnte.
Denn ich finde dass der Ausdruck konstant genug ist.

Ansonsten: Kennt jemand eine Alternative?
Michael
"Programmers talk about software development on weekends, vacations, and over meals not because they lack imagination,
but because their imagination reveals worlds that others cannot see."
  Mit Zitat antworten Zitat