2017-05-25 10:31:24 +02:00
|
|
|
unit InMemoryDataU;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
System.Generics.Collections,
|
2020-10-30 18:08:56 +01:00
|
|
|
BusinessObjectsU, Data.DB;
|
2017-05-25 10:31:24 +02:00
|
|
|
|
|
|
|
function GetPeopleList: TObjectList<TPerson>;
|
2020-10-30 18:08:56 +01:00
|
|
|
function GetDataSet: TDataSet;
|
2017-12-12 18:32:41 +01:00
|
|
|
function GetPeopleSmallList: TObjectList<TPerson>;
|
2019-10-10 20:16:20 +02:00
|
|
|
function GetInterfacedPeopleList: TList<IPerson>;
|
2017-05-25 10:31:24 +02:00
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
2020-10-30 18:08:56 +01:00
|
|
|
System.SysUtils, FireDAC.Comp.Client, Data.SqlTimSt;
|
2017-05-25 10:31:24 +02:00
|
|
|
|
|
|
|
var
|
2017-12-12 18:32:41 +01:00
|
|
|
GPeople, GPeopleSmall: TObjectList<TPerson>;
|
2017-05-25 10:31:24 +02:00
|
|
|
|
2019-10-10 20:16:20 +02:00
|
|
|
function GetInterfacedPeopleList: TList<IPerson>;
|
|
|
|
begin
|
2023-08-30 17:38:14 +02:00
|
|
|
Result := TList<IPerson>.Create([
|
|
|
|
TInterfacedPerson.Create('Daniele Teti', 40, EncodeDate(1979, 11, 4)),
|
|
|
|
TInterfacedPerson.Create('Peter Parker', 35, EncodeDate(1984, 11, 4))
|
|
|
|
]);
|
2019-10-10 20:16:20 +02:00
|
|
|
end;
|
|
|
|
|
2017-05-25 10:31:24 +02:00
|
|
|
procedure PopulateList;
|
|
|
|
var
|
|
|
|
p: TPerson;
|
|
|
|
I: Integer;
|
|
|
|
begin
|
|
|
|
GPeople := TObjectList<TPerson>.Create(True);
|
|
|
|
for I := 1 to 1000 do
|
|
|
|
begin
|
|
|
|
p := TPerson.Create;
|
|
|
|
p.FirstName := 'Daniele';
|
|
|
|
p.LastName := 'Teti';
|
|
|
|
p.DOB := EncodeDate(1979, 11, 4);
|
|
|
|
p.Married := True;
|
|
|
|
GPeople.Add(p);
|
|
|
|
|
|
|
|
p := TPerson.Create;
|
|
|
|
p.FirstName := 'John';
|
|
|
|
p.LastName := 'Doe';
|
|
|
|
p.DOB := EncodeDate(1879, 10, 2);
|
|
|
|
p.Married := False;
|
|
|
|
GPeople.Add(p);
|
|
|
|
|
|
|
|
p := TPerson.Create;
|
|
|
|
p.FirstName := 'Jane';
|
|
|
|
p.LastName := 'Doe';
|
|
|
|
p.DOB := EncodeDate(1883, 1, 5);
|
|
|
|
p.Married := True;
|
|
|
|
GPeople.Add(p);
|
|
|
|
end;
|
|
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
function GetPeopleList: TObjectList<TPerson>;
|
|
|
|
begin
|
|
|
|
Result := GPeople;
|
|
|
|
end;
|
|
|
|
|
2017-12-12 18:32:41 +01:00
|
|
|
procedure PopulateSmallList;
|
|
|
|
var
|
|
|
|
p: TPerson;
|
|
|
|
begin
|
|
|
|
GPeopleSmall := TObjectList<TPerson>.Create(True);
|
|
|
|
p := TPerson.Create;
|
|
|
|
p.FirstName := 'Daniele';
|
|
|
|
p.LastName := 'Teti';
|
|
|
|
p.DOB := EncodeDate(1979, 11, 4);
|
|
|
|
p.Married := True;
|
|
|
|
GPeopleSmall.Add(p);
|
|
|
|
|
|
|
|
p := TPerson.Create;
|
|
|
|
p.FirstName := 'John';
|
|
|
|
p.LastName := 'Doe';
|
|
|
|
p.DOB := EncodeDate(1879, 10, 2);
|
|
|
|
p.Married := False;
|
|
|
|
GPeopleSmall.Add(p);
|
|
|
|
|
|
|
|
p := TPerson.Create;
|
|
|
|
p.FirstName := 'Jane';
|
|
|
|
p.LastName := 'Doe';
|
|
|
|
p.DOB := EncodeDate(1883, 1, 5);
|
|
|
|
p.Married := True;
|
|
|
|
GPeopleSmall.Add(p);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function GetPeopleSmallList: TObjectList<TPerson>;
|
|
|
|
begin
|
|
|
|
Result := GPeopleSmall;
|
|
|
|
end;
|
|
|
|
|
2020-10-30 18:08:56 +01:00
|
|
|
function CreateDataSet: TFDMemTable;
|
|
|
|
var
|
|
|
|
lDS: TFDMemTable;
|
|
|
|
begin
|
|
|
|
lDS := TFDMemTable.Create(nil);
|
|
|
|
try
|
|
|
|
lDS.FieldDefs.Add('field_string', ftString, 20);
|
|
|
|
lDS.FieldDefs.Add('field_time', ftTime);
|
|
|
|
lDS.FieldDefs.Add('field_date', ftDate);
|
|
|
|
lDS.FieldDefs.Add('field_datetime', ftDateTime);
|
|
|
|
lDS.FieldDefs.Add('field_timestamp', ftTimeStamp);
|
|
|
|
// lDS.FieldDefs.Add('field_timestamp_with_offset', ftTimeStampOffset);
|
|
|
|
lDS.CreateDataSet;
|
|
|
|
Result := lDS;
|
|
|
|
except
|
|
|
|
lDS.Free;
|
|
|
|
raise;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function GetDataSet: TDataSet;
|
|
|
|
var
|
|
|
|
lDS: TFDMemTable;
|
|
|
|
I: Integer;
|
|
|
|
begin
|
|
|
|
lDS := CreateDataSet;
|
|
|
|
try
|
|
|
|
for I := 0 to 0 do
|
|
|
|
begin
|
|
|
|
lDS.Insert;
|
|
|
|
lDS.FieldByName('field_string').AsString := 'Field' + I.ToString;
|
|
|
|
lDS.FieldByName('field_time').AsDateTime := Time();
|
|
|
|
lDS.FieldByName('field_date').AsDateTime := Date();
|
|
|
|
lDS.FieldByName('field_datetime').AsDateTime := Now();
|
|
|
|
lDS.FieldByName('field_timestamp').AsSQLTimeStamp := DateTimeToSQLTimeStamp(Now());
|
|
|
|
// lDS.FieldByName('field_timestamp_with_offset').AsSQLTimeStampOffset := DateTimeToSQLTimeStampOffset(Now());
|
|
|
|
lDS.Post;
|
|
|
|
end;
|
|
|
|
except
|
|
|
|
lDS.Free;
|
|
|
|
raise;
|
|
|
|
end;
|
|
|
|
Result := lDS;
|
|
|
|
end;
|
|
|
|
|
2017-05-25 10:31:24 +02:00
|
|
|
initialization
|
|
|
|
|
|
|
|
PopulateList;
|
2017-12-12 18:32:41 +01:00
|
|
|
PopulateSmallList;
|
2017-05-25 10:31:24 +02:00
|
|
|
|
|
|
|
finalization
|
|
|
|
|
|
|
|
GPeople.Free;
|
2017-12-12 18:32:41 +01:00
|
|
|
GPeopleSmall.Free;
|
2017-05-25 10:31:24 +02:00
|
|
|
|
|
|
|
end.
|