I am new convert to Spring4D. I have been experimenting with it by converting some exiting code and I came across this:
{Using System.Generics.Collections}
TDenonInputList = class(TObjectList<TDenonInput>)
private
function GetInputByName(Name: string): TDenonInput;
function GetInputByRename(Name: string): TDenonInput;
public
constructor Create;
destructor Destroy; override;
procedure LockedAdd(ADenonInput: TDenonInput);
procedure LockedClear;
property Names[Name: string]: TDenonInput read GetInputByName;
property Renames[Name: string]: TDenonInput read GetInputByRename;
end;
So, I converted it by doing this:
{Using Spring4D.Collections.Lists}
IDenonInputList = interface(IList<TDenonInput>)
['{2201FB6B-1B9C-4FEE-9614-EFF2A7D35957}']
function GetInputByName(Name: string): TDenonInput;
function GetInputByRename(Name: string): TDenonInput;
procedure LockedAdd(ADenonInput: TDenonInput);
procedure LockedClear;
property Names[Name: string]: TDenonInput read GetInputByName;
property Renames[Name: string]: TDenonInput read GetInputByRename;
end;
TDenonInputList = class(TList<TDenonInput>, IDenonInputList)
private
function GetInputByName(Name: string): TDenonInput;
function GetInputByRename(Name: string): TDenonInput;
procedure LockedAdd(ADenonInput: TDenonInput);
procedure LockedClear;
public
constructor Create;
destructor Destroy; override;
end;
And then I create the new list type by doing this:
var
InputList: IDenonInputList;
begin
InputList := TDenonInputList.Create;
{...}
end;
However, I read that one should use the factory functions in TCollections to create Spring4D lists, such as TCollections.CreateList<T>
. Although what I have done seems to work fine, my question is: Is there a more correct way to create an instance of IDenonInputList, or is there a more proper way to create IList descendents and add additional functions/properties to an IList<T>
?