0

I still use Delphi XE4 (newest compiler I use of multiple Delphi compilers) and need a specific workaround for the fact they completely hid FClients in TBasicAction in this version. I connect/disconnect clients runtime while setting enabled/disabled (to avoid flicker with ~100+ actions and ui elements) thus this workaround for XE4:

Here's my naive attempt and simply returning the field.

  TmscBasicActionCrack = class(TBasicAction)
  end;
{$IFDEF mymsDELPHIXE4}
  TmscBasicActionHelper = class helper for TBasicAction
  public
    function Helper_Get_Private_FClients: TList<System.Classes.TBasicActionLink>;
  end;
{$ENDIF}

{$IFDEF mymsDELPHIXE4}
//------------------------------------------------------------------------------
function TmscBasicActionHelper.Helper_Get_Private_FClients: TList<System.Classes.TBasicActionLink>;
begin
  Result := Self.FClients;
end;
{$ENDIF}

However, I get error

E2003 Undeclared identifier: TList<>

I must admit I never go around to using generics with Delphi since I initially heard of stability problems + I need to maintain compability with Lazarus/FreePascal.

I am aware the most recent versions Delphi has altered class helpers again, but I am for now mostly interested in getting this to work with Delphi XE4

Tom
  • 3,587
  • 9
  • 69
  • 124
  • Please make as answer... And I will accept. Thanks :) – Tom Apr 10 '17 at 12:01
  • If you ever upgrade to Berlin or higher, your class helper will no longer work as-is, you would have to re-write it (see [How to access a private field from a class helper in Delphi 10.1 Berlin?](http://stackoverflow.com/questions/37351215/)). You should find a different solution to your problem. Why do you need direct access to the `FClients` list at all? It is private for a reason. – Remy Lebeau Apr 10 '17 at 20:01
  • I have a rather convoluted setup where 100+ actions are set enabled/disabled in onidle ... now unfortunately the rules are a bit complex (also partly riddled with defines since I have 6 different tools compiling/using exact same project and code) and some actions can be set twice (yes, I could create boolean values for all actions, work on them and then set actions) - that causes flicker in toolbars. My solution long ago was to disattach actions from their UI elements while updating the action states. – Tom Apr 10 '17 at 20:19
  • 2
    You should be updating the action states in the `OnUpdate` event of the individual actions, or in the `OnUpdate` event of the `TActionManager`, but not in the `Application.OnIdle` event itself. Also look at the `TApplication.ActionUpdateDelay` property (which is 0 by default). – Remy Lebeau Apr 10 '17 at 20:25
  • Thanks - I will try see if those are available in Lazarus as well ror maybe use those you list for Delphi in defines - I use the same codebase + forms for Delphi and Lazarus (Using Lazarus for targeting Mac) – Tom Apr 10 '17 at 21:10
  • `TAction` has an `OnUpdate` event in Lazarus. – Remy Lebeau Apr 10 '17 at 21:16

1 Answers1

8

The error is indicating that the TList<T> type is unknown to the compiler. To use it you must include System.Generics.Collections in your uses clause.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
J...
  • 30,968
  • 6
  • 66
  • 143