{$APPTYPE CONSOLE}
uses
Spring.Collections,
SysUtils;
type
TTest =
class
private
FValue: Double;
public
property Value: Double
read FValue
write FValue;
end;
ITestList = IList<TTest>;
function CopyTestList(
const SourceList: ITestList): ITestList;
var
i: Integer;
lTest: TTest;
begin
Result := TCollections.CreateObjectList<TTest>(True);
for i := 0
to SourceList.Count - 1
do
begin
lTest := TTest.Create;
lTest.Value := SourceList[i].Value;
Result.Add(lTest);
end;
end;
function DoAdding(
const SourceList: ITestList): ITestList;
var
i: Integer;
begin
Result := CopyTestList(SourceList);
for i := 0
to Result.Count - 1
do
Result[i].Value := Result[i].Value + 5;
end;
function DoMultiplicate(
const SourceList: ITestList): ITestList;
var
i: Integer;
begin
Result := CopyTestList(SourceList);
for i := 0
to Result.Count - 1
do
Result[i].Value := Result[i].Value * 5;
end;
var
FlagAddieren: Boolean;
FlagMultiplicate: Boolean;
function DoCalculations(
const SourceList: ITestList): ITestList;
var
temp: ITestList;
begin
temp := SourceList;
if FlagAddieren
then
temp := DoAdding(temp);
if FlagMultiplicate
then
temp := DoMultiplicate(temp);
Result := temp;
end;
procedure Start;
var
i: Integer;
lStartList, lResultList: ITestList;
lTest: TTest;
begin
lStartList := TCollections.CreateObjectList<TTest>(true);
for i := 1
to 5
do
begin
lTest := TTest.Create;
lStartList.Add(lTest);
lTest.Value := i;
end;
FlagAddieren := True;
FlagMultiplicate := True;
lResultList := DoCalculations(lStartList);
for lTest
in lResultList
do
Writeln(lTest.Value.ToString);
end;
begin
try
Start;
except
on E:
Exception do
Writeln(E.ClassName, '
: ', E.
Message);
end;
Readln;
end.