What replaces TEvent<T> ?

110 views
Skip to first unread message

obones

unread,
Nov 27, 2023, 9:55:18 AM11/27/23
to Spring4D
Hello,

As we are not doing updates to third party projects on a regular basis, we often struggle to keep up with changes but it was always a smooth ride with Spring4D.
Sadly, this time round, it's not as easy because of the following commit:

Revision: 4f2540cdddc5f4c509d95c6a4e107dfc4787a26b
Author: Stefan Glienke <-...@---.org>
Date: 03/12/2020 03:24:53
Message:
event optimizations

----
Modified: Source/Base/Collections/Spring.Collections.Events.pas
Modified: Source/Base/Spring.Events.Base.pas
Modified: Source/Base/Spring.Events.pas
Added: Source/Base/Spring.HazardEra.pas
Modified: Source/Base/Spring.ResourceStrings.pas
Modified: Source/Base/Spring.pas
Modified: Source/Core/Container/Spring.Container.Builder.pas
Modified: Tests/Source/Base/Spring.Tests.Base.pas
Modified: Tests/Source/Base/Spring.Tests.Collections.pas

In this commit, the TEvent<T> class has been removed altogether and we can't seem to find any obvious replacement to be used in our code.
Here is what we usually do:

type
  TOnFieldHashStringChanged = procedure(AField: TToolDataField) of object;

class
  TSomeClass = class
  private
    FOnHashStringChanged: IEvent<TOnFieldHashStringChanged>;
  public
    constructor Create;
  end;

constructor  TSomeClass.Create;
begin
  inherited Create;

  FOnHashStringChanged := TEvent<TOnFieldHashStringChanged>.Create;
end;

This used to work just fine, but now that we have updated Sprig4D it no longer compiles
As an interim measure, I have reintroduced the class myself in our local copy, but I'm not sure this is a viable long term solution.

Any suggestion is most welcome.

Regards
Olivier

Stefan Glienke

unread,
Nov 27, 2023, 10:00:36 AM11/27/23
to Spring4D
Just use the record type Event<T> - it auto initializes. If you want to expose the event to outside of your class then do that via the interfaces IEvent<T> or IInvokableEvent<T>, the getter will simply be an assignment of the field to Result (implicit overator overload handles that).

obones

unread,
Nov 27, 2023, 10:20:53 AM11/27/23
to Spring4D
So this means I need to change the field declaration from IEvent<> to Event<>, remove the initialization in the constructor, and introduce a getter for every property that already uses IEvent<> but accesses the field directly.

Quite cumbersome considering the amount of events that I have scattered all over the code base.

Stefan Glienke

unread,
Nov 27, 2023, 10:23:04 AM11/27/23
to Spring4D
Yes, which has been the recommended way for some while already.
Reply all
Reply to author
Forward
0 new messages