Can I have something like a TObjectList in Web Core?


I'm currently using a TObject list in my Pascal program, and I want to translate this functionality to Web Core application:

TComponentModeList = class(TObjectList)
    procedure SetObject(Index :Integer; Item: TComponentMode);
    function  GetObject(Index :Integer):TComponentMode;
    constructor Create; overload;

I'm getting this error when compiling with Web Core:

[Error] senCilleCustomWeb.pas(37): Generics without specialization cannot be used as a type for a variable

Is there a form to do this easily with Web Core?

At this moment, the pas2js RTL is not having this, but why not simply use a generic list specialized to the object type you want to use?

Ok. I found that TObjectList is in the Unit System.Cntnrs when I compile with Web Core. But I can't get it working.

When I Add an object I get the next error:

Cannot read properties of null (reading 'Add$1')

Next is the method used to add a member to this list.

function TscCustomWebForm.ModeListAdd(AComponent :TWebComponent; AMode: TMode):Integer;
var Component :TComponentMode;
   Component := TComponentMode.Create(AComponent, AMode);
   Result := FComponentModeList.Add(Component);
   if (Component.Component is TWebControl) then begin
      TWebControl(Component.Component).TabOrder := FComponentModeList.Count -1;

Yes, what I want, really is a list of TWebControls, but each one must be cualified with a "Mode".

Well. I found the solution.

First. The problem of Cannot read properties of null (reading 'Add$1') is the form of pas2js to say, "Access Violation error." At least in this case.

I'm using visual inheritance to have a standard set of behaviors in all application forms. While I took part of the code and ideas from my old FMX applications, I implemented the creation of the List Of Objects in the Create method of the parent form. ERRORRRRRR!!!!!

It must be the WebFormCreate method!!!!!!!

Anyway, I implemented it now instead of a TObjectList with a TDictionary.

I don't know if it will be more efficient, but the code will become simpler.