2016-09-18 19:19:23 +02:00
|
|
|
|
// ***************************************************************************
|
|
|
|
|
//
|
|
|
|
|
// Delphi MVC Framework
|
|
|
|
|
//
|
2023-01-17 08:52:26 +01:00
|
|
|
|
// Copyright (c) 2010-2023 Daniele Teti and the DMVCFramework Team
|
2016-09-18 19:19:23 +02:00
|
|
|
|
//
|
|
|
|
|
// https://github.com/danieleteti/delphimvcframework
|
|
|
|
|
//
|
|
|
|
|
// ***************************************************************************
|
|
|
|
|
//
|
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
//
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
//
|
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
|
// limitations under the License.
|
|
|
|
|
//
|
|
|
|
|
// *************************************************************************** }
|
|
|
|
|
|
2015-12-22 12:29:25 +01:00
|
|
|
|
unit BOs;
|
|
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
|
|
uses
|
2021-09-23 22:52:28 +02:00
|
|
|
|
system.TimeSpan, generics.collections, system.Classes,
|
2020-11-04 19:06:54 +01:00
|
|
|
|
system.Rtti, MVCFramework.Serializer.Commons, JsonDataObjects,
|
|
|
|
|
MVCFramework.ActiveRecord, MVCFramework.Nullables,
|
|
|
|
|
MVCFramework.SQLGenerators.SQLite, MVCFramework.SQLGenerators.Firebird,
|
2020-12-12 19:26:18 +01:00
|
|
|
|
MVCFramework.SQLGenerators.PostgreSQL,
|
2021-09-23 22:52:28 +02:00
|
|
|
|
FireDAC.Stan.Param, Data.DB, System.SysUtils;
|
2020-01-08 23:59:41 +01:00
|
|
|
|
|
|
|
|
|
const
|
2022-06-23 14:34:01 +02:00
|
|
|
|
SQLs_SQLITE: array [0 .. 6] of string =
|
2020-11-04 19:06:54 +01:00
|
|
|
|
('CREATE TABLE customers (id INTEGER NOT NULL, code varchar (20), description varchar (200), city varchar (200), note TEXT, rating INTEGER, creation_time TIME, creation_date date, PRIMARY KEY (id))',
|
2020-07-02 23:19:36 +02:00
|
|
|
|
'CREATE TABLE customers2 (id INTEGER NOT NULL, code varchar (20), description varchar (200), city varchar (200), note TEXT, rating INTEGER, creation_time TIME, creation_date date, PRIMARY KEY (id))',
|
2020-03-31 16:23:22 +02:00
|
|
|
|
'CREATE TABLE customers_with_code (code varchar (20) not null, description varchar (200), city varchar (200), note TEXT, rating INTEGER, PRIMARY KEY(code))',
|
2020-11-04 19:06:54 +01:00
|
|
|
|
'CREATE TABLE nullables_test(f_int2 int2, f_int8 int8, f_int4 int4, f_string varchar, f_bool BOOLEAN, '
|
|
|
|
|
+ 'f_date TIMESTAMP, f_time TIMESTAMP, f_datetime TIMESTAMP, f_float4 float4, f_float8 float8, '
|
2021-04-05 19:35:46 +02:00
|
|
|
|
+ 'f_currency numeric(18,4), f_blob BLOB)',
|
|
|
|
|
'CREATE TABLE "customers with spaces" ( ' +
|
|
|
|
|
'"id with spaces" integer primary key AUTOINCREMENT, ' +
|
|
|
|
|
'"code with spaces" text, ' +
|
|
|
|
|
'"description with spaces" text, ' +
|
|
|
|
|
'"city with spaces" text, ' +
|
|
|
|
|
'"note with spaces" text, ' +
|
|
|
|
|
'"rating with spaces" INTEGER, ' +
|
|
|
|
|
'"creation_time with spaces" TEXT, ' +
|
|
|
|
|
'"creation_date with spaces" TEXT' +
|
2022-04-12 12:12:08 +02:00
|
|
|
|
') ',
|
2022-06-23 14:34:01 +02:00
|
|
|
|
'CREATE TABLE booltest(id integer primary key AUTOINCREMENT, boolvalue integer)',
|
|
|
|
|
'CREATE TABLE CUSTOMERS_WITH_GUID (IDGUID text NOT NULL, OtherGUID text not null, CODE text, DESCRIPTION text, CITY text, NOTE text, RATING INTEGER, CONSTRAINT CUSTOMERS_WITH_GUID_PK PRIMARY KEY (IDGUID))'
|
2021-04-05 19:35:46 +02:00
|
|
|
|
);
|
2015-12-22 12:29:25 +01:00
|
|
|
|
|
2022-06-23 14:34:01 +02:00
|
|
|
|
SQLs_FIREBIRD: array [0 .. 6] of string =
|
2020-11-04 19:06:54 +01:00
|
|
|
|
('CREATE TABLE customers (id integer generated by default as identity primary key, code varchar (20), description varchar (200), city varchar (200), note varchar(200), rating INTEGER, creation_time TIME, creation_date date)',
|
2020-07-13 17:05:22 +02:00
|
|
|
|
'CREATE TABLE customers2 (id integer generated by default as identity primary key,code varchar (20), description varchar (200), city varchar (200), note varchar(200), rating INTEGER, creation_time TIME, creation_date date)',
|
|
|
|
|
'CREATE TABLE customers_with_code (code varchar (20) not null, description varchar (200), city varchar (200), note varchar(200), rating INTEGER, PRIMARY KEY(code))',
|
2020-09-21 12:42:38 +02:00
|
|
|
|
'CREATE TABLE nullables_test(f_int2 smallint, f_int8 bigint, f_int4 integer, f_string varchar(200), f_bool BOOLEAN, '
|
2020-11-04 19:06:54 +01:00
|
|
|
|
+ 'f_date TIMESTAMP, f_time TIMESTAMP, f_datetime TIMESTAMP, f_float4 float, f_float8 double precision, '
|
2021-04-05 19:35:46 +02:00
|
|
|
|
+ 'f_currency numeric(18,4), f_blob BLOB)',
|
|
|
|
|
'CREATE TABLE "customers with spaces" ( ' +
|
|
|
|
|
'"id with spaces" BIGINT generated by default as identity primary KEY, ' +
|
|
|
|
|
'"code with spaces" varchar(20), ' +
|
|
|
|
|
'"description with spaces" varchar(200), ' +
|
|
|
|
|
'"city with spaces" varchar(200), ' +
|
|
|
|
|
'"note with spaces" BLOB SUB_TYPE TEXT, ' +
|
|
|
|
|
'"rating with spaces" INTEGER, ' +
|
|
|
|
|
'"creation_time with spaces" time, ' +
|
|
|
|
|
'"creation_date with spaces" date' +
|
2022-04-12 12:12:08 +02:00
|
|
|
|
') ',
|
2022-06-23 14:34:01 +02:00
|
|
|
|
'CREATE TABLE booltest(id integer generated by default as identity primary key, boolvalue boolean)',
|
|
|
|
|
'CREATE TABLE CUSTOMERS_WITH_GUID (IDGUID VARCHAR(38) NOT NULL, OtherGUID VARCHAR(38) not null, CODE VARCHAR(20), DESCRIPTION VARCHAR(200), CITY VARCHAR(200), NOTE BLOB SUB_TYPE TEXT, RATING INTEGER, CONSTRAINT CUSTOMERS_WITH_GUID_PK PRIMARY KEY (IDGUID))'
|
2021-04-05 19:35:46 +02:00
|
|
|
|
);
|
2020-07-13 17:05:22 +02:00
|
|
|
|
|
2022-06-23 14:34:01 +02:00
|
|
|
|
SQLs_POSTGRESQL: array [0 .. 6] of string =
|
2020-12-12 19:26:18 +01:00
|
|
|
|
('CREATE TABLE customers (id integer generated by default as identity primary key, code varchar (20), description varchar (200), city varchar (200), note varchar(200), rating INTEGER, creation_time TIME, creation_date date)',
|
|
|
|
|
'CREATE TABLE customers2 (id integer generated by default as identity primary key,code varchar (20), description varchar (200), city varchar (200), note varchar(200), rating INTEGER, creation_time TIME, creation_date date)',
|
|
|
|
|
'CREATE TABLE customers_with_code (code varchar (20) not null, description varchar (200), city varchar (200), note varchar(200), rating INTEGER, PRIMARY KEY(code))',
|
|
|
|
|
'CREATE TABLE nullables_test(f_int2 smallint, f_int8 bigint, f_int4 integer, f_string varchar(200), f_bool BOOLEAN, '
|
2020-12-13 00:36:55 +01:00
|
|
|
|
+ 'f_date TIMESTAMP, f_time TIME, f_datetime TIMESTAMP, f_float4 float, f_float8 double precision, '
|
2021-04-05 19:35:46 +02:00
|
|
|
|
+ 'f_currency numeric(18,4), f_blob bytea)',
|
|
|
|
|
'CREATE TABLE public."customers with spaces" ( ' +
|
|
|
|
|
'"id with spaces" int8 generated by default as identity primary key, ' +
|
|
|
|
|
'"code with spaces" varchar(20) NULL, ' +
|
|
|
|
|
'"description with spaces" varchar(200) NULL, ' +
|
|
|
|
|
'"city with spaces" varchar(200) NULL, ' +
|
|
|
|
|
'"note with spaces" text NULL, ' +
|
|
|
|
|
'"rating with spaces" int4 NULL, ' +
|
|
|
|
|
'"creation_time with spaces" time NULL, ' +
|
|
|
|
|
'"creation_date with spaces" date NULL' +
|
2022-04-12 12:12:08 +02:00
|
|
|
|
')',
|
2022-06-23 14:34:01 +02:00
|
|
|
|
'CREATE TABLE booltest(id integer generated by default as identity primary key, boolvalue boolean)',
|
|
|
|
|
'CREATE TABLE customers_with_guid (idguid UUID NOT NULL, OtherGUID UUID not null, code VARCHAR(20), description VARCHAR(200), city VARCHAR(200), note varchar, RATING integer, CONSTRAINT CUSTOMERS_WITH_GUID_PK PRIMARY KEY (idguid))'
|
2021-04-05 19:35:46 +02:00
|
|
|
|
);
|
2020-12-12 19:26:18 +01:00
|
|
|
|
|
2015-12-22 12:29:25 +01:00
|
|
|
|
type
|
2020-01-08 23:59:41 +01:00
|
|
|
|
|
|
|
|
|
[MVCTable('customers')]
|
|
|
|
|
TCustomer = class(TMVCActiveRecord)
|
|
|
|
|
private
|
|
|
|
|
[MVCTableField('id', [foPrimaryKey, foAutoGenerated])]
|
2021-09-23 22:52:28 +02:00
|
|
|
|
fID: NullableInt32;
|
2020-01-08 23:59:41 +01:00
|
|
|
|
[MVCTableField('code')]
|
|
|
|
|
fCode: NullableString;
|
|
|
|
|
[MVCTableField('description')]
|
|
|
|
|
fCompanyName: NullableString;
|
|
|
|
|
[MVCTableField('city')]
|
|
|
|
|
fCity: string;
|
|
|
|
|
[MVCTableField('rating')]
|
2020-02-03 12:11:42 +01:00
|
|
|
|
fRating: NullableInt32;
|
2020-01-08 23:59:41 +01:00
|
|
|
|
[MVCTableField('note')]
|
2020-03-31 16:23:22 +02:00
|
|
|
|
fNote: string;
|
2020-06-25 23:19:00 +02:00
|
|
|
|
[MVCTableField('creation_time')]
|
|
|
|
|
fCreationTime: NullableTTime;
|
|
|
|
|
[MVCTableField('creation_date')]
|
|
|
|
|
fCreationDate: NullableTDate;
|
2020-01-08 23:59:41 +01:00
|
|
|
|
public
|
2022-10-09 15:45:59 +02:00
|
|
|
|
procedure Assign(Customer: TCustomer); reintroduce; overload;
|
2021-09-23 22:52:28 +02:00
|
|
|
|
function Clone: TCustomer;
|
|
|
|
|
function ToString: String; override;
|
|
|
|
|
property ID: NullableInt32 read fID write fID;
|
2022-08-02 23:57:09 +02:00
|
|
|
|
[MVCNameAs('CustomerCode')]
|
2020-01-08 23:59:41 +01:00
|
|
|
|
property Code: NullableString read fCode write fCode;
|
2020-02-03 13:19:55 +01:00
|
|
|
|
property CompanyName: NullableString read fCompanyName write fCompanyName;
|
2022-08-02 23:57:09 +02:00
|
|
|
|
[MVCNameAs('CityName')]
|
2020-02-03 13:19:55 +01:00
|
|
|
|
property City: string read fCity write fCity;
|
|
|
|
|
property Rating: NullableInt32 read fRating write fRating;
|
2020-06-25 23:19:00 +02:00
|
|
|
|
property CreationTime: NullableTTime read fCreationTime write fCreationTime;
|
|
|
|
|
property CreationDate: NullableTDate read fCreationDate write fCreationDate;
|
2020-03-31 16:23:22 +02:00
|
|
|
|
property Note: string read fNote write fNote;
|
|
|
|
|
end;
|
|
|
|
|
|
2021-11-18 17:52:06 +01:00
|
|
|
|
[MVCNameCase(ncLowerCase)]
|
|
|
|
|
[MVCTable('customers', 'ge(Rating,4)')]
|
|
|
|
|
TGoodCustomer = class(TCustomer)
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
[MVCNameCase(ncLowerCase)]
|
|
|
|
|
[MVCTable('customers', 'le(Rating,3)')]
|
|
|
|
|
TBadCustomer = class(TCustomer)
|
|
|
|
|
end;
|
|
|
|
|
|
2021-11-19 00:34:37 +01:00
|
|
|
|
|
|
|
|
|
[MVCTable('customers')]
|
|
|
|
|
TPartitionedCustomer = class(TMVCActiveRecord)
|
|
|
|
|
private
|
|
|
|
|
[MVCTableField('id', [foPrimaryKey, foAutoGenerated])]
|
|
|
|
|
fID: NullableInt32;
|
|
|
|
|
[MVCTableField('code')]
|
|
|
|
|
fCode: NullableString;
|
|
|
|
|
[MVCTableField('description')]
|
|
|
|
|
fCompanyName: NullableString;
|
|
|
|
|
[MVCTableField('note')]
|
|
|
|
|
fNote: string;
|
|
|
|
|
[MVCTableField('creation_time')]
|
|
|
|
|
fCreationTime: NullableTTime;
|
|
|
|
|
[MVCTableField('creation_date')]
|
|
|
|
|
fCreationDate: NullableTDate;
|
|
|
|
|
public
|
|
|
|
|
property ID: NullableInt32 read fID write fID;
|
|
|
|
|
property Code: NullableString read fCode write fCode;
|
|
|
|
|
property CompanyName: NullableString read fCompanyName write fCompanyName;
|
|
|
|
|
property CreationTime: NullableTTime read fCreationTime write fCreationTime;
|
|
|
|
|
property CreationDate: NullableTDate read fCreationDate write fCreationDate;
|
|
|
|
|
property Note: string read fNote write fNote;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
[MVCNameCase(ncLowerCase)]
|
|
|
|
|
[MVCTable('customers')]
|
|
|
|
|
[MVCPartition('rating=(integer)5')]
|
|
|
|
|
TCustomerR5 = class(TPartitionedCustomer)
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
[MVCNameCase(ncLowerCase)]
|
|
|
|
|
[MVCTable('customers')]
|
|
|
|
|
[MVCPartition('rating=(integer)4')]
|
|
|
|
|
TCustomerR4 = class(TPartitionedCustomer)
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
[MVCNameCase(ncLowerCase)]
|
|
|
|
|
[MVCTable('customers')]
|
|
|
|
|
[MVCPartition('city=(string)Rome')]
|
|
|
|
|
TRomeBasedCustomer = class(TPartitionedCustomer)
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
[MVCNameCase(ncLowerCase)]
|
|
|
|
|
[MVCTable('customers')]
|
|
|
|
|
[MVCPartition('city=(string)New York')]
|
|
|
|
|
TNewYorkBasedCustomer = class(TPartitionedCustomer)
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
[MVCNameCase(ncLowerCase)]
|
|
|
|
|
[MVCTable('customers')]
|
|
|
|
|
[MVCPartition('city=(string)New York;rating=(integer)5')]
|
|
|
|
|
TNewYorkBasedGoodCustomer = class(TPartitionedCustomer)
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
2020-03-31 16:23:22 +02:00
|
|
|
|
[MVCTable('customers_with_code')]
|
|
|
|
|
TCustomerWithCode = class(TMVCActiveRecord)
|
|
|
|
|
private
|
|
|
|
|
[MVCTableField('code', [foPrimaryKey])]
|
|
|
|
|
fCode: string;
|
|
|
|
|
[MVCTableField('description')]
|
|
|
|
|
fCompanyName: NullableString;
|
|
|
|
|
[MVCTableField('city')]
|
|
|
|
|
fCity: string;
|
|
|
|
|
[MVCTableField('rating')]
|
|
|
|
|
fRating: NullableInt32;
|
|
|
|
|
[MVCTableField('note')]
|
|
|
|
|
fNote: string;
|
|
|
|
|
public
|
|
|
|
|
property Code: string read fCode write fCode;
|
|
|
|
|
property CompanyName: NullableString read fCompanyName write fCompanyName;
|
|
|
|
|
property City: string read fCity write fCity;
|
|
|
|
|
property Rating: NullableInt32 read fRating write fRating;
|
|
|
|
|
property Note: string read fNote write fNote;
|
2020-02-03 13:19:55 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2021-04-05 19:35:46 +02:00
|
|
|
|
|
|
|
|
|
[MVCTable('customers with spaces')]
|
|
|
|
|
TCustomerWithSpaces = class(TMVCActiveRecord)
|
|
|
|
|
private
|
|
|
|
|
[MVCTableField('id with spaces', [foPrimaryKey, foAutoGenerated])]
|
|
|
|
|
fID: Integer;
|
|
|
|
|
[MVCTableField('code with spaces')]
|
|
|
|
|
fCode: NullableString;
|
|
|
|
|
[MVCTableField('description with spaces')]
|
|
|
|
|
fCompanyName: NullableString;
|
|
|
|
|
[MVCTableField('city with spaces')]
|
|
|
|
|
fCity: string;
|
|
|
|
|
[MVCTableField('rating with spaces')]
|
|
|
|
|
fRating: NullableInt32;
|
|
|
|
|
[MVCTableField('note with spaces')]
|
|
|
|
|
fNote: string;
|
|
|
|
|
[MVCTableField('creation_time with spaces')]
|
|
|
|
|
fCreationTime: NullableTTime;
|
|
|
|
|
[MVCTableField('creation_date with spaces')]
|
|
|
|
|
fCreationDate: NullableTDate;
|
|
|
|
|
public
|
|
|
|
|
property ID: Integer read fID write fID;
|
|
|
|
|
property Code: NullableString read fCode write fCode;
|
|
|
|
|
property CompanyName: NullableString read fCompanyName write fCompanyName;
|
|
|
|
|
property City: string read fCity write fCity;
|
|
|
|
|
property Rating: NullableInt32 read fRating write fRating;
|
|
|
|
|
property CreationTime: NullableTTime read fCreationTime write fCreationTime;
|
|
|
|
|
property CreationDate: NullableTDate read fCreationDate write fCreationDate;
|
|
|
|
|
property Note: string read fNote write fNote;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
2020-02-03 13:19:55 +01:00
|
|
|
|
[MVCTable('customers')]
|
|
|
|
|
TCustomerWithNullablePK = class(TMVCActiveRecord)
|
|
|
|
|
private
|
|
|
|
|
[MVCTableField('id', [foPrimaryKey, foAutoGenerated])]
|
|
|
|
|
fID: NullableInt64;
|
|
|
|
|
[MVCTableField('code')]
|
|
|
|
|
fCode: NullableString;
|
|
|
|
|
[MVCTableField('description')]
|
|
|
|
|
fCompanyName: NullableString;
|
|
|
|
|
[MVCTableField('city')]
|
|
|
|
|
fCity: string;
|
|
|
|
|
[MVCTableField('rating')]
|
|
|
|
|
fRating: NullableInt32;
|
|
|
|
|
[MVCTableField('note')]
|
2020-03-31 16:23:22 +02:00
|
|
|
|
fNote: string;
|
2020-02-03 13:19:55 +01:00
|
|
|
|
public
|
|
|
|
|
property ID: NullableInt64 read fID write fID;
|
|
|
|
|
property Code: NullableString read fCode write fCode;
|
2020-01-08 23:59:41 +01:00
|
|
|
|
property CompanyName: NullableString read fCompanyName write fCompanyName;
|
|
|
|
|
property City: string read fCity write fCity;
|
2020-02-03 12:11:42 +01:00
|
|
|
|
property Rating: NullableInt32 read fRating write fRating;
|
2020-03-31 16:23:22 +02:00
|
|
|
|
property Note: string read fNote write fNote;
|
2020-01-08 23:59:41 +01:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
[MVCTable('customers')]
|
|
|
|
|
TCustomerWithLF = class(TCustomer)
|
|
|
|
|
private
|
2020-03-31 16:23:22 +02:00
|
|
|
|
fHistory: TList<string>;
|
2020-01-08 23:59:41 +01:00
|
|
|
|
public
|
|
|
|
|
constructor Create; override;
|
|
|
|
|
destructor Destroy; override;
|
2020-03-31 16:23:22 +02:00
|
|
|
|
function GetHistory: string;
|
2020-01-08 23:59:41 +01:00
|
|
|
|
procedure ClearHistory;
|
|
|
|
|
protected
|
2020-03-31 00:47:35 +02:00
|
|
|
|
procedure OnValidation(const Action: TMVCEntityAction); override;
|
2020-01-08 23:59:41 +01:00
|
|
|
|
procedure OnAfterLoad; override;
|
|
|
|
|
procedure OnBeforeLoad; override;
|
|
|
|
|
procedure OnBeforeInsert; override;
|
|
|
|
|
procedure OnAfterInsert; override;
|
|
|
|
|
procedure OnBeforeUpdate; override;
|
|
|
|
|
procedure OnAfterUpdate; override;
|
|
|
|
|
procedure OnBeforeDelete; override;
|
|
|
|
|
procedure OnAfterDelete; override;
|
|
|
|
|
procedure OnBeforeInsertOrUpdate; override;
|
2020-03-31 16:23:22 +02:00
|
|
|
|
procedure OnBeforeExecuteSQL(var SQL: string); override;
|
2020-01-08 23:59:41 +01:00
|
|
|
|
procedure OnAfterInsertOrUpdate; override;
|
2020-12-12 19:26:18 +01:00
|
|
|
|
procedure MapObjectToParams(const Params: TFDParams; var Handled: Boolean); override;
|
2020-11-04 19:06:54 +01:00
|
|
|
|
procedure MapDatasetToObject(const DataSet: TDataSet;
|
2020-12-12 19:26:18 +01:00
|
|
|
|
const Options: TMVCActiveRecordLoadOptions; var Handled: Boolean); override;
|
2020-01-08 23:59:41 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2022-06-23 14:34:01 +02:00
|
|
|
|
[MVCNameCase(ncLowerCase)]
|
|
|
|
|
[MVCTable('customers_with_guid')]
|
|
|
|
|
TCustomerWithGUID = class(TMVCActiveRecord)
|
|
|
|
|
private
|
|
|
|
|
[MVCTableField('idguid', [foPrimaryKey])]
|
|
|
|
|
fGUID: NullableTGUID;
|
|
|
|
|
[MVCTableField('otherguid')]
|
|
|
|
|
fOtherGUID: TGUID;
|
|
|
|
|
[MVCTableField('code')]
|
|
|
|
|
fCode: NullableString;
|
|
|
|
|
[MVCTableField('description')]
|
|
|
|
|
fCompanyName: NullableString;
|
|
|
|
|
[MVCTableField('city')]
|
|
|
|
|
fCity: string;
|
|
|
|
|
[MVCTableField('rating')]
|
|
|
|
|
fRating: NullableInt32;
|
|
|
|
|
[MVCTableField('note')]
|
|
|
|
|
fNote: string;
|
|
|
|
|
public
|
|
|
|
|
property GUID: NullableTGUID read fGUID write fGUID;
|
|
|
|
|
property OtherGUID: TGUID read fOtherGUID write fOtherGUID;
|
|
|
|
|
property Code: NullableString read fCode write fCode;
|
|
|
|
|
property CompanyName: NullableString read fCompanyName write fCompanyName;
|
|
|
|
|
property City: string read fCity write fCity;
|
|
|
|
|
property Rating: NullableInt32 read fRating write fRating;
|
|
|
|
|
property Note: string read fNote write fNote;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
2020-01-08 23:59:41 +01:00
|
|
|
|
[MVCTable('nullables_test')]
|
|
|
|
|
TNullablesTest = class(TMVCActiveRecord)
|
|
|
|
|
private
|
2022-11-10 18:30:11 +01:00
|
|
|
|
[MVCTableField('f_int2', [foPrimaryKey])]
|
2020-01-08 23:59:41 +01:00
|
|
|
|
ff_int2: NullableInt16;
|
|
|
|
|
[MVCTableField('f_int4')]
|
|
|
|
|
ff_int4: NullableInt32;
|
|
|
|
|
[MVCTableField('f_int8')]
|
|
|
|
|
ff_int8: NullableInt64;
|
|
|
|
|
[MVCTableField('f_date')]
|
2020-02-03 12:11:42 +01:00
|
|
|
|
ff_date: NullableTDate;
|
2020-01-08 23:59:41 +01:00
|
|
|
|
[MVCTableField('f_time')]
|
2020-02-03 12:11:42 +01:00
|
|
|
|
ff_time: NullableTTime;
|
2020-01-08 23:59:41 +01:00
|
|
|
|
[MVCTableField('f_bool')]
|
|
|
|
|
ff_bool: NullableBoolean;
|
|
|
|
|
[MVCTableField('f_datetime')]
|
2020-02-03 12:11:42 +01:00
|
|
|
|
ff_datetime: NullableTDateTime;
|
2020-01-08 23:59:41 +01:00
|
|
|
|
[MVCTableField('f_float4')]
|
|
|
|
|
ff_float4: NullableSingle;
|
|
|
|
|
[MVCTableField('f_float8')]
|
|
|
|
|
ff_float8: NullableDouble;
|
|
|
|
|
[MVCTableField('f_string')]
|
|
|
|
|
ff_string: NullableString;
|
|
|
|
|
[MVCTableField('f_currency')]
|
|
|
|
|
ff_currency: NullableCurrency;
|
|
|
|
|
[MVCTableField('f_blob')]
|
|
|
|
|
ff_blob: TStream;
|
|
|
|
|
public
|
|
|
|
|
destructor Destroy; override;
|
|
|
|
|
// f_int2 int2 NULL,
|
|
|
|
|
property f_int2: NullableInt16 read ff_int2 write ff_int2;
|
|
|
|
|
// f_int4 int4 NULL,
|
|
|
|
|
property f_int4: NullableInt32 read ff_int4 write ff_int4;
|
|
|
|
|
// f_int8 int8 NULL,
|
|
|
|
|
property f_int8: NullableInt64 read ff_int8 write ff_int8;
|
|
|
|
|
// f_string varchar NULL,
|
|
|
|
|
property f_string: NullableString read ff_string write ff_string;
|
|
|
|
|
// f_bool bool NULL,
|
|
|
|
|
property f_bool: NullableBoolean read ff_bool write ff_bool;
|
|
|
|
|
// f_date date NULL,
|
2020-02-03 12:11:42 +01:00
|
|
|
|
property f_date: NullableTDate read ff_date write ff_date;
|
2020-01-08 23:59:41 +01:00
|
|
|
|
// f_time time NULL,
|
2020-02-03 12:11:42 +01:00
|
|
|
|
property f_time: NullableTTime read ff_time write ff_time;
|
2020-01-08 23:59:41 +01:00
|
|
|
|
// f_datetime timestamp NULL,
|
2020-02-03 12:11:42 +01:00
|
|
|
|
property f_datetime: NullableTDateTime read ff_datetime write ff_datetime;
|
2020-01-08 23:59:41 +01:00
|
|
|
|
// f_float4 float4 NULL,
|
|
|
|
|
property f_float4: NullableSingle read ff_float4 write ff_float4;
|
|
|
|
|
// f_float8 float8 NULL,
|
|
|
|
|
property f_float8: NullableDouble read ff_float8 write ff_float8;
|
|
|
|
|
// f_currency numeric(18,4) NULL
|
|
|
|
|
property f_currency: NullableCurrency read ff_currency write ff_currency;
|
|
|
|
|
// f_blob bytea NULL
|
|
|
|
|
property f_blob: TStream read ff_blob write ff_blob;
|
|
|
|
|
end;
|
|
|
|
|
|
2022-04-12 12:12:08 +02:00
|
|
|
|
|
|
|
|
|
[MVCTable('booltest')]
|
|
|
|
|
TBoolTest = class(TMVCActiveRecord)
|
|
|
|
|
private
|
|
|
|
|
[MVCTableField('id', [foPrimaryKey, foAutoGenerated])]
|
|
|
|
|
fID: NullableInt32;
|
|
|
|
|
[MVCTableField('boolvalue')]
|
|
|
|
|
fBoolValue: Boolean;
|
|
|
|
|
public
|
|
|
|
|
property ID: NullableInt32 read FID write fID;
|
|
|
|
|
property BoolValue: Boolean read FBoolValue write fBoolValue;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
2015-12-22 12:29:25 +01:00
|
|
|
|
TMyObject = class
|
|
|
|
|
private
|
|
|
|
|
FPropString: string;
|
|
|
|
|
FPropAnsiString: AnsiString;
|
|
|
|
|
FPropInt64: Int64;
|
|
|
|
|
FPropUInt32: cardinal;
|
|
|
|
|
FPropUInt64: UInt64;
|
|
|
|
|
FPropUInt16: word;
|
|
|
|
|
FPropInt16: smallint;
|
2020-01-08 23:59:41 +01:00
|
|
|
|
FPropBoolean: Boolean;
|
2015-12-22 12:29:25 +01:00
|
|
|
|
FPropDateTime: TDateTime;
|
|
|
|
|
FPropDate: TDate;
|
|
|
|
|
FPropInteger: Integer;
|
|
|
|
|
FPropTimeStamp: TTimeStamp;
|
|
|
|
|
FPropTime: TTime;
|
|
|
|
|
FPropCurrency: Currency;
|
2019-11-05 14:40:39 +01:00
|
|
|
|
fPropJSONObject: TJSONObject;
|
2015-12-22 12:29:25 +01:00
|
|
|
|
procedure SetPropAnsiString(const Value: AnsiString);
|
|
|
|
|
procedure SetPropString(const Value: string);
|
|
|
|
|
procedure SetPropInt64(const Value: Int64);
|
|
|
|
|
procedure SetPropUInt32(const Value: cardinal);
|
|
|
|
|
procedure SetPropUInt64(const Value: UInt64);
|
|
|
|
|
procedure SetPropInt16(const Value: smallint);
|
|
|
|
|
procedure SetPropUInt16(const Value: word);
|
2020-01-08 23:59:41 +01:00
|
|
|
|
procedure SetPropBoolean(const Value: Boolean);
|
2015-12-22 12:29:25 +01:00
|
|
|
|
procedure SetPropDate(const Value: TDate);
|
|
|
|
|
procedure SetPropDateTime(const Value: TDateTime);
|
|
|
|
|
procedure SetPropInteger(const Value: Integer);
|
|
|
|
|
procedure SetPropTimeStamp(const Value: TTimeStamp);
|
|
|
|
|
procedure SetPropTime(const Value: TTime);
|
|
|
|
|
procedure SetPropCurrency(const Value: Currency);
|
|
|
|
|
public
|
2019-11-05 14:40:39 +01:00
|
|
|
|
constructor Create;
|
|
|
|
|
destructor Destroy; override;
|
2020-01-08 23:59:41 +01:00
|
|
|
|
function Equals(Obj: TMyObject): Boolean; reintroduce;
|
2015-12-22 12:29:25 +01:00
|
|
|
|
property PropString: string read FPropString write SetPropString;
|
2020-12-12 19:26:18 +01:00
|
|
|
|
property PropAnsiString: AnsiString read FPropAnsiString write SetPropAnsiString;
|
2015-12-22 12:29:25 +01:00
|
|
|
|
property PropInteger: Integer read FPropInteger write SetPropInteger;
|
|
|
|
|
property PropUInt32: cardinal read FPropUInt32 write SetPropUInt32;
|
|
|
|
|
property PropInt64: Int64 read FPropInt64 write SetPropInt64;
|
|
|
|
|
property PropUInt64: UInt64 read FPropUInt64 write SetPropUInt64;
|
|
|
|
|
property PropUInt16: word read FPropUInt16 write SetPropUInt16;
|
|
|
|
|
property PropInt16: smallint read FPropInt16 write SetPropInt16;
|
2020-01-08 23:59:41 +01:00
|
|
|
|
property PropBoolean: Boolean read FPropBoolean write SetPropBoolean;
|
2015-12-22 12:29:25 +01:00
|
|
|
|
property PropDate: TDate read FPropDate write SetPropDate;
|
|
|
|
|
property PropTime: TTime read FPropTime write SetPropTime;
|
|
|
|
|
property PropDateTime: TDateTime read FPropDateTime write SetPropDateTime;
|
2020-12-12 19:26:18 +01:00
|
|
|
|
property PropTimeStamp: TTimeStamp read FPropTimeStamp write SetPropTimeStamp;
|
2015-12-22 12:29:25 +01:00
|
|
|
|
property PropCurrency: Currency read FPropCurrency write SetPropCurrency;
|
2019-11-05 14:40:39 +01:00
|
|
|
|
property PropJSONObject: TJSONObject read fPropJSONObject;
|
2015-12-22 12:29:25 +01:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
TMyChildObject = class
|
|
|
|
|
private
|
|
|
|
|
FMyChildProperty1: string;
|
|
|
|
|
procedure SetMyChildProperty1(const Value: string);
|
|
|
|
|
public
|
|
|
|
|
constructor Create;
|
2020-12-12 19:26:18 +01:00
|
|
|
|
property MyChildProperty1: string read FMyChildProperty1 write SetMyChildProperty1;
|
2015-12-22 12:29:25 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2020-11-04 19:06:54 +01:00
|
|
|
|
TMyObjectWithUTC = class(TObject)
|
|
|
|
|
private
|
|
|
|
|
FMyDateTime: TDateTime;
|
|
|
|
|
procedure SetMyDateTime(const Value: TDateTime);
|
|
|
|
|
public
|
|
|
|
|
function Equals(Obj: TObject): Boolean; override;
|
|
|
|
|
property MyDateTime: TDateTime read FMyDateTime write SetMyDateTime;
|
|
|
|
|
end;
|
|
|
|
|
|
2017-02-09 11:24:18 +01:00
|
|
|
|
TMyObjectWithTValue = class
|
|
|
|
|
private
|
|
|
|
|
FValueAsString: TValue;
|
|
|
|
|
FValueAsInteger: TValue;
|
|
|
|
|
FValue1: TValue;
|
|
|
|
|
FValue2: TValue;
|
|
|
|
|
FValue3: TValue;
|
|
|
|
|
FValue4: TValue;
|
|
|
|
|
FValue5: TValue;
|
|
|
|
|
procedure SetValueAsInteger(const Value: TValue);
|
|
|
|
|
procedure SetValueAsString(const Value: TValue);
|
|
|
|
|
public
|
2020-01-08 23:59:41 +01:00
|
|
|
|
function Equals(Obj: TObject): Boolean; reintroduce;
|
2017-08-21 15:31:31 +02:00
|
|
|
|
// [TValueAsType(TypeInfo(String))]
|
2017-02-09 11:24:18 +01:00
|
|
|
|
property ValueAsString: TValue read FValueAsString write SetValueAsString;
|
2017-08-21 15:31:31 +02:00
|
|
|
|
// [TValueAsType(TypeInfo(Integer))]
|
2020-12-12 19:26:18 +01:00
|
|
|
|
property ValueAsInteger: TValue read FValueAsInteger write SetValueAsInteger;
|
2017-02-09 11:24:18 +01:00
|
|
|
|
property Value1: TValue read FValue1 write FValue1;
|
|
|
|
|
property Value2: TValue read FValue2 write FValue2;
|
|
|
|
|
property Value3: TValue read FValue3 write FValue3;
|
|
|
|
|
property Value4: TValue read FValue4 write FValue4;
|
|
|
|
|
property Value5: TValue read FValue5 write FValue5;
|
|
|
|
|
end;
|
|
|
|
|
|
2017-06-22 16:18:58 +02:00
|
|
|
|
[MVCListOf(TMyChildObject)]
|
2015-12-22 12:29:25 +01:00
|
|
|
|
TMyChildObjectList = class(TObjectList<TMyChildObject>)
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
TMyComplexObject = class
|
|
|
|
|
private
|
2020-05-04 12:39:54 +02:00
|
|
|
|
fProp1: string;
|
|
|
|
|
fChildObjectList: TMyChildObjectList;
|
|
|
|
|
fChildObject: TMyChildObject;
|
|
|
|
|
fPropStringList: TStringList;
|
2015-12-22 12:29:25 +01:00
|
|
|
|
procedure SetChildObject(const Value: TMyChildObject);
|
|
|
|
|
procedure SetChildObjectList(const Value: TMyChildObjectList);
|
|
|
|
|
procedure SetProp1(const Value: string);
|
2017-02-09 19:33:59 +01:00
|
|
|
|
procedure SetPropStringList(const Value: TStringList);
|
2015-12-22 12:29:25 +01:00
|
|
|
|
public
|
|
|
|
|
constructor Create;
|
|
|
|
|
destructor Destroy; override;
|
2020-01-08 23:59:41 +01:00
|
|
|
|
function Equals(Obj: TObject): Boolean; override;
|
2015-12-22 12:29:25 +01:00
|
|
|
|
|
2020-05-04 12:39:54 +02:00
|
|
|
|
property Prop1: string read fProp1 write SetProp1;
|
2020-12-12 19:26:18 +01:00
|
|
|
|
property PropStringList: TStringList read fPropStringList write SetPropStringList;
|
2020-05-04 12:39:54 +02:00
|
|
|
|
property ChildObject: TMyChildObject read fChildObject write SetChildObject;
|
2020-12-12 19:26:18 +01:00
|
|
|
|
property ChildObjectList: TMyChildObjectList read fChildObjectList write SetChildObjectList;
|
2015-12-22 12:29:25 +01:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
TMyStreamObject = class(TObject)
|
|
|
|
|
private
|
|
|
|
|
FPropStream: TStream;
|
|
|
|
|
FProp8Stream: TStream;
|
2016-03-23 00:29:56 +01:00
|
|
|
|
FImageStream: TStream;
|
2015-12-22 12:29:25 +01:00
|
|
|
|
procedure SetPropStream(const Value: TStream);
|
|
|
|
|
procedure SetProp8Stream(const Value: TStream);
|
2016-03-23 00:29:56 +01:00
|
|
|
|
procedure SetImageStream(const Value: TStream);
|
2015-12-22 12:29:25 +01:00
|
|
|
|
public
|
2020-01-08 23:59:41 +01:00
|
|
|
|
function Equals(Obj: TMyStreamObject): Boolean; reintroduce;
|
2015-12-22 12:29:25 +01:00
|
|
|
|
constructor Create;
|
|
|
|
|
destructor Destroy; override;
|
2017-08-21 15:31:31 +02:00
|
|
|
|
[MVCSerializeAsString]
|
2015-12-22 12:29:25 +01:00
|
|
|
|
property PropStream: TStream read FPropStream write SetPropStream;
|
2017-08-21 15:31:31 +02:00
|
|
|
|
[MVCSerializeAsString]
|
2015-12-22 12:29:25 +01:00
|
|
|
|
// utf-8 is default
|
|
|
|
|
property Prop8Stream: TStream read FProp8Stream write SetProp8Stream;
|
2016-03-23 00:29:56 +01:00
|
|
|
|
property ImageStream: TStream read FImageStream write SetImageStream;
|
2015-12-22 12:29:25 +01:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
TMyObjectWithLogic = class
|
|
|
|
|
private
|
|
|
|
|
FLastName: string;
|
|
|
|
|
FFirstName: string;
|
|
|
|
|
FAge: Integer;
|
|
|
|
|
function GetFullName: string;
|
|
|
|
|
procedure SetFirstName(const Value: string);
|
|
|
|
|
procedure SetLastName(const Value: string);
|
2020-01-08 23:59:41 +01:00
|
|
|
|
function GetIsAdult: Boolean;
|
2015-12-22 12:29:25 +01:00
|
|
|
|
procedure SetAge(const Value: Integer);
|
|
|
|
|
public
|
|
|
|
|
constructor Create(aFirstName, aLastName: string; aAge: Integer);
|
2020-01-08 23:59:41 +01:00
|
|
|
|
function Equals(Obj: TObject): Boolean; override;
|
2015-12-22 12:29:25 +01:00
|
|
|
|
property FirstName: string read FFirstName write SetFirstName;
|
|
|
|
|
property LastName: string read FLastName write SetLastName;
|
|
|
|
|
property Age: Integer read FAge write SetAge;
|
2020-01-08 23:59:41 +01:00
|
|
|
|
property IsAdult: Boolean read GetIsAdult;
|
2015-12-22 12:29:25 +01:00
|
|
|
|
property FullName: string read GetFullName;
|
|
|
|
|
end;
|
|
|
|
|
|
2016-11-27 23:17:20 +01:00
|
|
|
|
TMyClass = class
|
|
|
|
|
private
|
2020-01-08 23:59:41 +01:00
|
|
|
|
fID: Integer;
|
2016-11-27 23:17:20 +01:00
|
|
|
|
FDescription: string;
|
|
|
|
|
procedure SetId(ID: Integer);
|
|
|
|
|
procedure SetDescription(Description: string);
|
|
|
|
|
public
|
2020-01-08 23:59:41 +01:00
|
|
|
|
function Equals(Obj: TObject): Boolean; override;
|
|
|
|
|
property ID: Integer read fID write SetId;
|
2016-11-27 23:17:20 +01:00
|
|
|
|
property Description: string read FDescription write SetDescription;
|
|
|
|
|
constructor Create(ID: Integer; Description: string); overload;
|
|
|
|
|
end;
|
|
|
|
|
|
2017-02-09 19:33:59 +01:00
|
|
|
|
IMyInterface = interface
|
|
|
|
|
['{B36E786B-5871-4211-88AD-365B453DC408}']
|
|
|
|
|
function GetID: Integer;
|
2017-08-21 15:31:31 +02:00
|
|
|
|
function GetDescription: string;
|
2017-02-09 19:33:59 +01:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
TMyIntfObject = class(TInterfacedObject, IMyInterface)
|
|
|
|
|
private
|
2020-01-08 23:59:41 +01:00
|
|
|
|
fID: Integer;
|
2017-02-09 19:33:59 +01:00
|
|
|
|
FValue: string;
|
|
|
|
|
public
|
2017-08-21 15:31:31 +02:00
|
|
|
|
constructor Create(const ID: Integer; const Value: string);
|
2017-02-09 19:33:59 +01:00
|
|
|
|
function GetDescription: string;
|
|
|
|
|
function GetID: Integer;
|
|
|
|
|
end;
|
|
|
|
|
|
2016-11-27 23:17:20 +01:00
|
|
|
|
TResponseWrapper<T: class> = class
|
|
|
|
|
private
|
|
|
|
|
FTotalItems: Integer;
|
|
|
|
|
FItems: TObjectList<T>;
|
|
|
|
|
procedure SetTotalItems(TotalItems: Integer);
|
|
|
|
|
procedure SetItems(aItems: TObjectList<T>);
|
|
|
|
|
public
|
|
|
|
|
property TotalItems: Integer read FTotalItems write SetTotalItems;
|
|
|
|
|
property Items: TObjectList<T> read FItems write SetItems;
|
|
|
|
|
constructor Create(TotalItems: Integer; aItems: TObjectList<T>); overload;
|
|
|
|
|
destructor Destroy; override;
|
|
|
|
|
end;
|
|
|
|
|
|
2017-02-09 19:33:59 +01:00
|
|
|
|
TObjectWithCustomType = class
|
|
|
|
|
private
|
2020-05-04 12:39:54 +02:00
|
|
|
|
fPropStringList: TStringList;
|
2017-08-21 15:31:31 +02:00
|
|
|
|
FPropStringArray: TArray<string>;
|
2017-02-10 14:19:55 +01:00
|
|
|
|
FPropStreamAsBASE64: TStringStream;
|
|
|
|
|
FPropStreamAsString: TStringStream;
|
2017-02-09 19:33:59 +01:00
|
|
|
|
procedure SetPropStringList(const Value: TStringList);
|
2017-08-21 15:31:31 +02:00
|
|
|
|
procedure SetPropStringArray(const Value: TArray<string>);
|
2017-02-10 14:19:55 +01:00
|
|
|
|
procedure SetPropStreamAsBASE64(const Value: TStringStream);
|
|
|
|
|
procedure SetPropStreamAsString(const Value: TStringStream);
|
2017-02-09 19:33:59 +01:00
|
|
|
|
public
|
|
|
|
|
constructor Create; virtual;
|
|
|
|
|
destructor Destroy; override;
|
2020-01-08 23:59:41 +01:00
|
|
|
|
function Equals(Obj: TObject): Boolean; override;
|
2020-12-12 19:26:18 +01:00
|
|
|
|
property PropStringList: TStringList read fPropStringList write SetPropStringList;
|
|
|
|
|
property PropStringArray: TArray<string> read FPropStringArray write SetPropStringArray;
|
2017-02-10 14:19:55 +01:00
|
|
|
|
[MVCSerializeAsString]
|
2020-12-12 19:26:18 +01:00
|
|
|
|
property PropStreamAsString: TStringStream read FPropStreamAsString write SetPropStreamAsString;
|
|
|
|
|
property PropStreamAsBASE64: TStringStream read FPropStreamAsBASE64 write SetPropStreamAsBASE64;
|
2017-02-09 19:33:59 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2020-05-04 12:39:54 +02:00
|
|
|
|
[MVCNameCase(ncLowerCase)]
|
|
|
|
|
TPartialSerializableType = class
|
|
|
|
|
private
|
|
|
|
|
fProp1: string;
|
|
|
|
|
fProp2: string;
|
|
|
|
|
fProp3: string;
|
|
|
|
|
fProp4: string;
|
|
|
|
|
public
|
|
|
|
|
constructor Create;
|
|
|
|
|
[MVCDoNotSerialize]
|
|
|
|
|
property Prop1: string read fProp1 write fProp1;
|
|
|
|
|
[MVCDoNotDeSerialize]
|
|
|
|
|
property Prop2: string read fProp2 write fProp2;
|
|
|
|
|
[MVCDoNotSerialize]
|
|
|
|
|
[MVCDoNotDeSerialize]
|
|
|
|
|
property Prop3: string read fProp3 write fProp3;
|
|
|
|
|
property Prop4: string read fProp4 write fProp4;
|
|
|
|
|
end;
|
|
|
|
|
|
2020-09-21 12:42:38 +02:00
|
|
|
|
TListOfSomething = class
|
|
|
|
|
private
|
|
|
|
|
fListOfString: TList<string>;
|
|
|
|
|
fListOfInteger: TList<Integer>;
|
|
|
|
|
fListOfBoolean: TList<Boolean>;
|
|
|
|
|
fListOfDouble: TList<Double>;
|
|
|
|
|
// fListOfListOfString: TList<TList<string>>;
|
|
|
|
|
public
|
|
|
|
|
property ListOfString: TList<string> read fListOfString;
|
|
|
|
|
property ListOfInteger: TList<Integer> read fListOfInteger;
|
|
|
|
|
property ListOfBoolean: TList<Boolean> read fListOfBoolean;
|
|
|
|
|
property ListOfDouble: TList<Double> read fListOfDouble;
|
|
|
|
|
// property ListOfListOfString: TList < TList < string >> read fListOfListOfString;
|
|
|
|
|
constructor Create;
|
|
|
|
|
destructor Destroy; override;
|
|
|
|
|
end;
|
|
|
|
|
|
2015-12-22 12:29:25 +01:00
|
|
|
|
function GetMyObject: TMyObject;
|
2017-02-09 11:24:18 +01:00
|
|
|
|
function GetMyObjectWithTValue: TMyObjectWithTValue;
|
2017-02-08 18:29:52 +01:00
|
|
|
|
function GetMyObjectWithStream: TMyStreamObject;
|
2015-12-22 12:29:25 +01:00
|
|
|
|
function GetMyComplexObject: TMyComplexObject;
|
|
|
|
|
function GetMyComplexObjectWithNotInitializedChilds: TMyComplexObject;
|
2017-02-10 14:19:55 +01:00
|
|
|
|
function GetMyObjectWithCustomType: TObjectWithCustomType;
|
2015-12-22 12:29:25 +01:00
|
|
|
|
|
2017-02-08 18:29:52 +01:00
|
|
|
|
const
|
|
|
|
|
BASE64_STRING: AnsiString = 'This is serialized as BASE64 String';
|
|
|
|
|
|
2015-12-22 12:29:25 +01:00
|
|
|
|
implementation
|
|
|
|
|
|
|
|
|
|
uses
|
2017-02-08 18:29:52 +01:00
|
|
|
|
system.DateUtils, Winapi.Windows;
|
2015-12-22 12:29:25 +01:00
|
|
|
|
|
2017-02-10 14:19:55 +01:00
|
|
|
|
function GetMyObjectWithCustomType: TObjectWithCustomType;
|
|
|
|
|
begin
|
|
|
|
|
Result := TObjectWithCustomType.Create;
|
|
|
|
|
Result.PropStringList.Add('item 1');
|
|
|
|
|
Result.PropStringList.Add('item 2');
|
|
|
|
|
Result.PropStringList.Add('item 3');
|
|
|
|
|
Result.PropStringList.Add('item 4');
|
|
|
|
|
Result.PropStringArray := ['item 1', 'item 2', 'item 3', 'item 4'];
|
|
|
|
|
Result.PropStreamAsString.WriteString('This is a string');
|
|
|
|
|
Result.PropStreamAsBASE64.WriteString('This is a BASE64 string');
|
|
|
|
|
end;
|
|
|
|
|
|
2015-12-22 12:29:25 +01:00
|
|
|
|
function GetMyComplexObjectWithNotInitializedChilds: TMyComplexObject;
|
|
|
|
|
begin
|
|
|
|
|
Result := TMyComplexObject.Create;
|
|
|
|
|
Result.Prop1 := 'property1';
|
|
|
|
|
end;
|
|
|
|
|
|
2017-02-09 11:24:18 +01:00
|
|
|
|
function GetMyObjectWithTValue: TMyObjectWithTValue;
|
|
|
|
|
begin
|
|
|
|
|
Result := TMyObjectWithTValue.Create;
|
|
|
|
|
Result.ValueAsString := 'Value As String';
|
|
|
|
|
Result.ValueAsInteger := 1234;
|
|
|
|
|
Result.Value1 := 'Hello World';
|
|
|
|
|
Result.Value2 := 1234;
|
|
|
|
|
Result.Value3 := true;
|
|
|
|
|
Result.Value4 := 1234.5678;
|
|
|
|
|
// VALUE5 must be a floting number bacause of equals check
|
|
|
|
|
Result.Value5 := EncodeDateTime(2004, 6, 7, 11, 30, 0, 0);
|
|
|
|
|
end;
|
|
|
|
|
|
2015-12-22 12:29:25 +01:00
|
|
|
|
function GetMyComplexObject: TMyComplexObject;
|
|
|
|
|
var
|
|
|
|
|
co: TMyChildObject;
|
|
|
|
|
begin
|
|
|
|
|
Result := TMyComplexObject.Create;
|
|
|
|
|
Result.Prop1 := 'property1';
|
2017-02-09 19:33:59 +01:00
|
|
|
|
Result.PropStringList := TStringList.Create;
|
|
|
|
|
Result.PropStringList.Add('item 1');
|
|
|
|
|
Result.PropStringList.Add('item 2');
|
|
|
|
|
Result.PropStringList.Add('item 3');
|
|
|
|
|
Result.PropStringList.Add('item 4');
|
2015-12-22 12:29:25 +01:00
|
|
|
|
Result.ChildObject.MyChildProperty1 := 'MySingleChildProperty1';
|
|
|
|
|
co := TMyChildObject.Create;
|
|
|
|
|
co.MyChildProperty1 := 'MyChildProperty1';
|
|
|
|
|
Result.ChildObjectList.Add(co);
|
|
|
|
|
co := TMyChildObject.Create;
|
|
|
|
|
co.MyChildProperty1 := 'MyChildProperty2';
|
|
|
|
|
Result.ChildObjectList.Add(co);
|
|
|
|
|
co := TMyChildObject.Create;
|
|
|
|
|
co.MyChildProperty1 := 'MyChildProperty3';
|
|
|
|
|
Result.ChildObjectList.Add(co);
|
|
|
|
|
co := TMyChildObject.Create;
|
|
|
|
|
co.MyChildProperty1 := 'MyChildProperty4';
|
|
|
|
|
Result.ChildObjectList.Add(co);
|
|
|
|
|
end;
|
|
|
|
|
|
2017-02-08 18:29:52 +01:00
|
|
|
|
function GetMyObjectWithStream: TMyStreamObject;
|
|
|
|
|
var
|
|
|
|
|
Buff: TBytes;
|
|
|
|
|
begin
|
|
|
|
|
Result := TMyStreamObject.Create;
|
|
|
|
|
TStringStream(Result.PropStream).WriteString('This is an UTF16 String');
|
|
|
|
|
TStringStream(Result.Prop8Stream).WriteString('This is an UTF8 String');
|
|
|
|
|
SetLength(Buff, Length(BASE64_STRING));
|
|
|
|
|
MoveMemory(Buff, PAnsiChar(AnsiString(BASE64_STRING)), Length(BASE64_STRING));
|
|
|
|
|
TMemoryStream(Result.ImageStream).Write(Buff, Length(Buff));
|
|
|
|
|
end;
|
|
|
|
|
|
2015-12-22 12:29:25 +01:00
|
|
|
|
function GetMyObject: TMyObject;
|
|
|
|
|
begin
|
|
|
|
|
Result := TMyObject.Create;
|
|
|
|
|
Result.PropString := 'Some text <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>';
|
|
|
|
|
Result.PropAnsiString := 'This is an ANSI text';
|
2016-03-23 00:29:56 +01:00
|
|
|
|
Result.PropInteger := -1234;
|
2015-12-22 12:29:25 +01:00
|
|
|
|
Result.PropUInt32 := 1234;
|
2016-03-23 00:29:56 +01:00
|
|
|
|
Result.PropInt64 := -1234567890;
|
2015-12-22 12:29:25 +01:00
|
|
|
|
Result.PropUInt64 := 1234567890;
|
|
|
|
|
Result.PropUInt16 := 12345;
|
2016-03-23 00:29:56 +01:00
|
|
|
|
Result.PropInt16 := -12345;
|
2015-12-22 12:29:25 +01:00
|
|
|
|
Result.PropCurrency := 1234.5678;
|
|
|
|
|
Result.PropBoolean := true;
|
|
|
|
|
Result.PropDate := EncodeDate(2010, 10, 20);
|
|
|
|
|
Result.PropTime := EncodeTime(10, 20, 30, 40);
|
|
|
|
|
Result.PropDateTime := Result.PropDate + Result.PropTime;
|
|
|
|
|
Result.PropTimeStamp := DateTimeToTimeStamp(Result.PropDateTime + 1);
|
2019-11-05 14:40:39 +01:00
|
|
|
|
Result.PropJSONObject.S['stringprop1'] := 'This is a string prop';
|
|
|
|
|
Result.PropJSONObject.I['intprop1'] := 1234;
|
|
|
|
|
Result.PropJSONObject.A['arrprop'].Add(1234);
|
|
|
|
|
Result.PropJSONObject.A['arrprop'].Add('Hello World');
|
|
|
|
|
Result.PropJSONObject.O['objprop'].S['innerprop1'] := 'value1';
|
|
|
|
|
Result.PropJSONObject.O['objprop'].S['innerprop2'] := 'value2';
|
|
|
|
|
Result.PropJSONObject.O['objprop'].S['innerprop3'] := 'value3';
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
constructor TMyObject.Create;
|
|
|
|
|
begin
|
|
|
|
|
inherited;
|
2020-01-08 23:59:41 +01:00
|
|
|
|
fPropJSONObject := TJSONObject.Create;
|
2019-11-05 14:40:39 +01:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
destructor TMyObject.Destroy;
|
|
|
|
|
begin
|
|
|
|
|
fPropJSONObject.Free;
|
|
|
|
|
inherited;
|
2015-12-22 12:29:25 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2020-01-08 23:59:41 +01:00
|
|
|
|
function TMyObject.Equals(Obj: TMyObject): Boolean;
|
2022-04-05 17:17:35 +02:00
|
|
|
|
var
|
|
|
|
|
lMyStr: string;
|
|
|
|
|
lOtherStr: string;
|
2015-12-22 12:29:25 +01:00
|
|
|
|
begin
|
|
|
|
|
Result := true;
|
|
|
|
|
Result := Result and (Self.PropString = Obj.PropString);
|
|
|
|
|
Result := Result and (Self.PropAnsiString = Obj.PropAnsiString);
|
|
|
|
|
Result := Result and (Self.PropInteger = Obj.PropInteger);
|
|
|
|
|
Result := Result and (Self.PropUInt32 = Obj.PropUInt32);
|
|
|
|
|
Result := Result and (Self.PropInt64 = Obj.PropInt64);
|
|
|
|
|
Result := Result and (Self.PropUInt64 = Obj.PropUInt64);
|
|
|
|
|
Result := Result and (Self.PropUInt16 = Obj.PropUInt16);
|
|
|
|
|
Result := Result and (Self.PropInt16 = Obj.PropInt16);
|
|
|
|
|
Result := Result and (Self.PropBoolean = Obj.PropBoolean);
|
|
|
|
|
Result := Result and (Self.PropDate = Obj.PropDate);
|
|
|
|
|
Result := Result and (Self.PropCurrency = Obj.PropCurrency);
|
|
|
|
|
Result := Result and (SecondsBetween(Self.PropTime, Obj.PropTime) = 0);
|
2020-12-12 19:26:18 +01:00
|
|
|
|
Result := Result and (SecondsBetween(Self.PropDateTime, Obj.PropDateTime) = 0);
|
2015-12-22 12:29:25 +01:00
|
|
|
|
Result := Result and (Self.PropTimeStamp.Date = Obj.PropTimeStamp.Date) and
|
|
|
|
|
(Self.PropTimeStamp.Time = Obj.PropTimeStamp.Time);
|
2022-04-05 17:17:35 +02:00
|
|
|
|
lMyStr := Self.fPropJSONObject.ToJSON();
|
|
|
|
|
lOtherStr := Obj.PropJSONObject.ToJSON();
|
2020-12-12 19:26:18 +01:00
|
|
|
|
Result := Result and (Self.fPropJSONObject.ToJSON() = Obj.PropJSONObject.ToJSON());
|
2015-12-22 12:29:25 +01:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMyObject.SetPropAnsiString(const Value: AnsiString);
|
|
|
|
|
begin
|
|
|
|
|
FPropAnsiString := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
2020-01-08 23:59:41 +01:00
|
|
|
|
procedure TMyObject.SetPropBoolean(const Value: Boolean);
|
2015-12-22 12:29:25 +01:00
|
|
|
|
begin
|
|
|
|
|
FPropBoolean := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMyObject.SetPropCurrency(const Value: Currency);
|
|
|
|
|
begin
|
|
|
|
|
FPropCurrency := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMyObject.SetPropDate(const Value: TDate);
|
|
|
|
|
begin
|
|
|
|
|
FPropDate := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMyObject.SetPropDateTime(const Value: TDateTime);
|
|
|
|
|
begin
|
|
|
|
|
FPropDateTime := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMyObject.SetPropInt16(const Value: smallint);
|
|
|
|
|
begin
|
|
|
|
|
FPropInt16 := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMyObject.SetPropInt64(const Value: Int64);
|
|
|
|
|
begin
|
|
|
|
|
FPropInt64 := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMyObject.SetPropInteger(const Value: Integer);
|
|
|
|
|
begin
|
|
|
|
|
FPropInteger := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMyObject.SetPropString(const Value: string);
|
|
|
|
|
begin
|
|
|
|
|
FPropString := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMyObject.SetPropTime(const Value: TTime);
|
|
|
|
|
begin
|
|
|
|
|
FPropTime := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMyObject.SetPropTimeStamp(const Value: TTimeStamp);
|
|
|
|
|
begin
|
|
|
|
|
FPropTimeStamp := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMyObject.SetPropUInt16(const Value: word);
|
|
|
|
|
begin
|
|
|
|
|
FPropUInt16 := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMyObject.SetPropUInt32(const Value: cardinal);
|
|
|
|
|
begin
|
|
|
|
|
FPropUInt32 := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMyObject.SetPropUInt64(const Value: UInt64);
|
|
|
|
|
begin
|
|
|
|
|
FPropUInt64 := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
{ TMyComplexObject }
|
|
|
|
|
|
|
|
|
|
constructor TMyComplexObject.Create;
|
|
|
|
|
begin
|
|
|
|
|
inherited;
|
2020-05-04 12:39:54 +02:00
|
|
|
|
fChildObjectList := TMyChildObjectList.Create(true);
|
|
|
|
|
fChildObject := TMyChildObject.Create;
|
2015-12-22 12:29:25 +01:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
destructor TMyComplexObject.Destroy;
|
|
|
|
|
begin
|
2020-05-04 12:39:54 +02:00
|
|
|
|
fChildObjectList.Free;
|
|
|
|
|
fChildObject.Free;
|
|
|
|
|
fPropStringList.Free;
|
2015-12-22 12:29:25 +01:00
|
|
|
|
inherited;
|
|
|
|
|
end;
|
|
|
|
|
|
2020-01-08 23:59:41 +01:00
|
|
|
|
function TMyComplexObject.Equals(Obj: TObject): Boolean;
|
2015-12-22 12:29:25 +01:00
|
|
|
|
var
|
|
|
|
|
co: TMyComplexObject;
|
|
|
|
|
begin
|
|
|
|
|
co := Obj as TMyComplexObject;
|
|
|
|
|
|
|
|
|
|
Result := co.Prop1 = Self.Prop1;
|
|
|
|
|
if Assigned(co.ChildObject) and Assigned(Self.ChildObject) then
|
2020-12-12 19:26:18 +01:00
|
|
|
|
Result := Result and (co.ChildObject.MyChildProperty1 = Self.ChildObject.MyChildProperty1)
|
2015-12-22 12:29:25 +01:00
|
|
|
|
else
|
2020-12-12 19:26:18 +01:00
|
|
|
|
Result := Result and (not Assigned(co.ChildObject)) and (not Assigned(Self.ChildObject));
|
2015-12-22 12:29:25 +01:00
|
|
|
|
Result := Result and (co.ChildObjectList.Count = Self.ChildObjectList.Count);
|
|
|
|
|
if co.ChildObjectList.Count = 0 then
|
|
|
|
|
Exit;
|
|
|
|
|
|
2020-12-12 19:26:18 +01:00
|
|
|
|
Result := Result and (co.ChildObjectList[0].MyChildProperty1 = Self.ChildObjectList[0]
|
2015-12-22 12:29:25 +01:00
|
|
|
|
.MyChildProperty1);
|
2020-12-12 19:26:18 +01:00
|
|
|
|
Result := Result and (co.ChildObjectList[1].MyChildProperty1 = Self.ChildObjectList[1]
|
2015-12-22 12:29:25 +01:00
|
|
|
|
.MyChildProperty1);
|
2020-12-12 19:26:18 +01:00
|
|
|
|
Result := Result and (co.ChildObjectList[2].MyChildProperty1 = Self.ChildObjectList[2]
|
2015-12-22 12:29:25 +01:00
|
|
|
|
.MyChildProperty1);
|
2020-12-12 19:26:18 +01:00
|
|
|
|
Result := Result and (co.ChildObjectList[3].MyChildProperty1 = Self.ChildObjectList[3]
|
2015-12-22 12:29:25 +01:00
|
|
|
|
.MyChildProperty1);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMyComplexObject.SetChildObject(const Value: TMyChildObject);
|
|
|
|
|
begin
|
2020-05-04 12:39:54 +02:00
|
|
|
|
fChildObject := Value;
|
2015-12-22 12:29:25 +01:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMyComplexObject.SetChildObjectList(const Value: TMyChildObjectList);
|
|
|
|
|
begin
|
2020-05-04 12:39:54 +02:00
|
|
|
|
fChildObjectList := Value;
|
2015-12-22 12:29:25 +01:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMyComplexObject.SetProp1(const Value: string);
|
|
|
|
|
begin
|
2020-05-04 12:39:54 +02:00
|
|
|
|
fProp1 := Value;
|
2015-12-22 12:29:25 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2017-02-09 19:33:59 +01:00
|
|
|
|
procedure TMyComplexObject.SetPropStringList(const Value: TStringList);
|
|
|
|
|
begin
|
2020-05-04 12:39:54 +02:00
|
|
|
|
fPropStringList := Value;
|
2017-02-09 19:33:59 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2015-12-22 12:29:25 +01:00
|
|
|
|
{ TMyChildObject }
|
|
|
|
|
|
|
|
|
|
constructor TMyChildObject.Create;
|
|
|
|
|
begin
|
|
|
|
|
inherited;
|
|
|
|
|
Self.MyChildProperty1 := 'my default value';
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMyChildObject.SetMyChildProperty1(const Value: string);
|
|
|
|
|
begin
|
|
|
|
|
FMyChildProperty1 := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
{ TMyStreamObject }
|
|
|
|
|
|
|
|
|
|
constructor TMyStreamObject.Create;
|
|
|
|
|
begin
|
|
|
|
|
inherited Create;
|
|
|
|
|
FPropStream := TStringStream.Create('', TEncoding.Unicode);
|
|
|
|
|
FProp8Stream := TStringStream.Create('', TEncoding.UTF8);
|
2016-03-23 00:29:56 +01:00
|
|
|
|
FImageStream := TMemoryStream.Create;
|
2015-12-22 12:29:25 +01:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
destructor TMyStreamObject.Destroy;
|
|
|
|
|
begin
|
2017-02-08 18:29:52 +01:00
|
|
|
|
FPropStream.Free;
|
|
|
|
|
FProp8Stream.Free;
|
|
|
|
|
FImageStream.Free;
|
2015-12-22 12:29:25 +01:00
|
|
|
|
inherited;
|
|
|
|
|
end;
|
|
|
|
|
|
2020-01-08 23:59:41 +01:00
|
|
|
|
function TMyStreamObject.Equals(Obj: TMyStreamObject): Boolean;
|
2017-02-08 18:29:52 +01:00
|
|
|
|
var
|
|
|
|
|
lPMemSelf: PByte;
|
|
|
|
|
lPMemOther: PByte;
|
|
|
|
|
I: Integer;
|
|
|
|
|
begin
|
|
|
|
|
Result := true;
|
2020-12-12 19:26:18 +01:00
|
|
|
|
Result := Result and (TStringStream(Self.PropStream).DataString = TStringStream(Obj.PropStream)
|
|
|
|
|
.DataString);
|
|
|
|
|
Result := Result and (TStringStream(Self.Prop8Stream).DataString = TStringStream(Obj.Prop8Stream)
|
|
|
|
|
.DataString);
|
2017-02-08 18:29:52 +01:00
|
|
|
|
Result := Result and (Self.ImageStream.Size = Obj.ImageStream.Size);
|
|
|
|
|
|
|
|
|
|
if Result then
|
|
|
|
|
begin
|
|
|
|
|
lPMemSelf := TMemoryStream(Self.ImageStream).Memory;
|
|
|
|
|
lPMemOther := TMemoryStream(Obj.ImageStream).Memory;
|
|
|
|
|
for I := 0 to Self.ImageStream.Size - 1 do
|
|
|
|
|
begin
|
|
|
|
|
Result := Result and (lPMemSelf^ = lPMemOther^);
|
|
|
|
|
Inc(lPMemSelf);
|
|
|
|
|
Inc(lPMemOther);
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
2016-03-23 00:29:56 +01:00
|
|
|
|
procedure TMyStreamObject.SetImageStream(const Value: TStream);
|
|
|
|
|
begin
|
|
|
|
|
FImageStream := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
2015-12-22 12:29:25 +01:00
|
|
|
|
procedure TMyStreamObject.SetProp8Stream(const Value: TStream);
|
|
|
|
|
begin
|
|
|
|
|
if Assigned(FProp8Stream) then
|
2017-02-08 18:29:52 +01:00
|
|
|
|
FreeAndNil(FProp8Stream);
|
2015-12-22 12:29:25 +01:00
|
|
|
|
FProp8Stream := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMyStreamObject.SetPropStream(const Value: TStream);
|
|
|
|
|
begin
|
|
|
|
|
if Assigned(FPropStream) then
|
|
|
|
|
FPropStream.Free;
|
|
|
|
|
FPropStream := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
{ TCliente }
|
|
|
|
|
|
|
|
|
|
{ TMyObjectWithLogic }
|
|
|
|
|
|
2020-12-12 19:26:18 +01:00
|
|
|
|
constructor TMyObjectWithLogic.Create(aFirstName, aLastName: string; aAge: Integer);
|
2015-12-22 12:29:25 +01:00
|
|
|
|
begin
|
|
|
|
|
inherited Create;
|
|
|
|
|
FFirstName := aFirstName;
|
|
|
|
|
FLastName := aLastName;
|
|
|
|
|
FAge := aAge;
|
|
|
|
|
end;
|
|
|
|
|
|
2020-01-08 23:59:41 +01:00
|
|
|
|
function TMyObjectWithLogic.Equals(Obj: TObject): Boolean;
|
2015-12-22 12:29:25 +01:00
|
|
|
|
var
|
|
|
|
|
lOther: TMyObjectWithLogic;
|
|
|
|
|
begin
|
|
|
|
|
Result := (Obj is TMyObjectWithLogic);
|
|
|
|
|
if Result then
|
|
|
|
|
begin
|
|
|
|
|
lOther := TMyObjectWithLogic(Obj);
|
|
|
|
|
Result := Result and (Self.FirstName = lOther.FirstName);
|
|
|
|
|
Result := Result and (Self.LastName = lOther.LastName);
|
|
|
|
|
Result := Result and (Self.Age = lOther.Age);
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TMyObjectWithLogic.GetFullName: string;
|
|
|
|
|
begin
|
|
|
|
|
Result := FirstName + ' ' + LastName; // logic
|
|
|
|
|
end;
|
|
|
|
|
|
2020-01-08 23:59:41 +01:00
|
|
|
|
function TMyObjectWithLogic.GetIsAdult: Boolean;
|
2015-12-22 12:29:25 +01:00
|
|
|
|
begin
|
|
|
|
|
Result := Age >= 18; // logic
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMyObjectWithLogic.SetAge(const Value: Integer);
|
|
|
|
|
begin
|
|
|
|
|
FAge := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMyObjectWithLogic.SetFirstName(const Value: string);
|
|
|
|
|
begin
|
|
|
|
|
FFirstName := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMyObjectWithLogic.SetLastName(const Value: string);
|
|
|
|
|
begin
|
|
|
|
|
FLastName := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
2016-11-27 23:17:20 +01:00
|
|
|
|
{ TResponseGrid<T> }
|
|
|
|
|
|
2020-12-12 19:26:18 +01:00
|
|
|
|
constructor TResponseWrapper<T>.Create(TotalItems: Integer; aItems: TObjectList<T>);
|
2016-11-27 23:17:20 +01:00
|
|
|
|
begin
|
|
|
|
|
inherited Create;
|
|
|
|
|
Self.SetTotalItems(TotalItems);
|
|
|
|
|
Self.SetItems(aItems);
|
2017-02-08 18:29:52 +01:00
|
|
|
|
aItems.OwnsObjects := true;
|
2016-11-27 23:17:20 +01:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
destructor TResponseWrapper<T>.Destroy;
|
|
|
|
|
begin
|
|
|
|
|
FItems.Free;
|
|
|
|
|
inherited;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TResponseWrapper<T>.SetItems(aItems: TObjectList<T>);
|
|
|
|
|
begin
|
|
|
|
|
Self.FItems := aItems;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TResponseWrapper<T>.SetTotalItems(TotalItems: Integer);
|
|
|
|
|
begin
|
|
|
|
|
Self.FTotalItems := TotalItems;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
{ TMyClass }
|
|
|
|
|
|
|
|
|
|
constructor TMyClass.Create(ID: Integer; Description: string);
|
|
|
|
|
begin
|
|
|
|
|
inherited Create;
|
|
|
|
|
Self.SetId(ID);
|
|
|
|
|
Self.SetDescription(Description);
|
|
|
|
|
end;
|
|
|
|
|
|
2020-01-08 23:59:41 +01:00
|
|
|
|
function TMyClass.Equals(Obj: TObject): Boolean;
|
2017-02-10 18:48:02 +01:00
|
|
|
|
begin
|
|
|
|
|
Result := Obj is TMyClass;
|
|
|
|
|
if Result then
|
|
|
|
|
begin
|
|
|
|
|
Result := Result and (TMyClass(Obj).ID = ID);
|
|
|
|
|
Result := Result and (TMyClass(Obj).Description = Description);
|
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
2016-11-27 23:17:20 +01:00
|
|
|
|
procedure TMyClass.SetDescription(Description: string);
|
|
|
|
|
begin
|
|
|
|
|
Self.FDescription := Description;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMyClass.SetId(ID: Integer);
|
|
|
|
|
begin
|
2020-01-08 23:59:41 +01:00
|
|
|
|
Self.fID := ID;
|
2016-11-27 23:17:20 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2017-02-09 11:24:18 +01:00
|
|
|
|
{ TMyObjectWithTValue }
|
|
|
|
|
|
2020-01-08 23:59:41 +01:00
|
|
|
|
function TMyObjectWithTValue.Equals(Obj: TObject): Boolean;
|
2017-02-09 11:24:18 +01:00
|
|
|
|
var
|
|
|
|
|
lOther: TMyObjectWithTValue;
|
|
|
|
|
begin
|
|
|
|
|
Result := Obj is TMyObjectWithTValue;
|
|
|
|
|
if Result then
|
|
|
|
|
begin
|
|
|
|
|
lOther := TMyObjectWithTValue(Obj);
|
2020-12-12 19:26:18 +01:00
|
|
|
|
Result := Result and (Self.ValueAsString.AsString = lOther.ValueAsString.AsString);
|
|
|
|
|
Result := Result and (Self.ValueAsInteger.AsInteger = lOther.ValueAsInteger.AsInteger);
|
2017-02-09 11:24:18 +01:00
|
|
|
|
Result := Result and (Self.Value1.AsVariant = lOther.Value1.AsVariant);
|
|
|
|
|
Result := Result and (Self.Value2.AsVariant = lOther.Value2.AsVariant);
|
|
|
|
|
Result := Result and (Self.Value3.AsVariant = lOther.Value3.AsVariant);
|
|
|
|
|
Result := Result and (Self.Value4.AsVariant = lOther.Value4.AsVariant);
|
2020-11-04 19:06:54 +01:00
|
|
|
|
Result := Result and (Trunc(Self.Value5.AsVariant * 100000)
|
|
|
|
|
= Trunc(lOther.Value5.AsVariant * 100000));
|
2017-02-09 11:24:18 +01:00
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMyObjectWithTValue.SetValueAsInteger(const Value: TValue);
|
|
|
|
|
begin
|
|
|
|
|
FValueAsInteger := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMyObjectWithTValue.SetValueAsString(const Value: TValue);
|
|
|
|
|
begin
|
|
|
|
|
FValueAsString := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
2017-02-09 19:33:59 +01:00
|
|
|
|
{ TMyIntfObject }
|
|
|
|
|
|
2017-08-21 15:31:31 +02:00
|
|
|
|
constructor TMyIntfObject.Create(const ID: Integer; const Value: string);
|
2017-02-09 19:33:59 +01:00
|
|
|
|
begin
|
|
|
|
|
inherited Create;
|
2020-01-08 23:59:41 +01:00
|
|
|
|
fID := ID;
|
2017-02-09 19:33:59 +01:00
|
|
|
|
FValue := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TMyIntfObject.GetDescription: string;
|
|
|
|
|
begin
|
|
|
|
|
Result := FValue;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TMyIntfObject.GetID: Integer;
|
|
|
|
|
begin
|
2020-01-08 23:59:41 +01:00
|
|
|
|
Result := fID;
|
2017-02-09 19:33:59 +01:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
{ TObjectWithCustomType }
|
|
|
|
|
|
|
|
|
|
constructor TObjectWithCustomType.Create;
|
|
|
|
|
begin
|
|
|
|
|
inherited;
|
2020-05-04 12:39:54 +02:00
|
|
|
|
fPropStringList := TStringList.Create;
|
2017-02-10 14:19:55 +01:00
|
|
|
|
FPropStreamAsString := TStringStream.Create;
|
|
|
|
|
FPropStreamAsBASE64 := TStringStream.Create;
|
2017-02-09 19:33:59 +01:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
destructor TObjectWithCustomType.Destroy;
|
|
|
|
|
begin
|
2020-05-04 12:39:54 +02:00
|
|
|
|
fPropStringList.Free;
|
2017-02-10 14:19:55 +01:00
|
|
|
|
FPropStreamAsString.Free;
|
|
|
|
|
FPropStreamAsBASE64.Free;
|
2017-02-09 19:33:59 +01:00
|
|
|
|
inherited;
|
|
|
|
|
end;
|
|
|
|
|
|
2020-01-08 23:59:41 +01:00
|
|
|
|
function TObjectWithCustomType.Equals(Obj: TObject): Boolean;
|
2017-02-10 14:19:55 +01:00
|
|
|
|
var
|
|
|
|
|
lOther: TObjectWithCustomType;
|
|
|
|
|
begin
|
|
|
|
|
if not(Obj is TObjectWithCustomType) then
|
|
|
|
|
Exit(false);
|
|
|
|
|
lOther := TObjectWithCustomType(Obj);
|
|
|
|
|
Result := true;
|
|
|
|
|
Result := Result and (lOther.PropStringList.Text = Self.PropStringList.Text);
|
2020-12-12 19:26:18 +01:00
|
|
|
|
Result := Result and (string.Join(',', lOther.PropStringArray) = string.Join(',',
|
|
|
|
|
Self.PropStringArray));
|
|
|
|
|
Result := Result and (lOther.PropStreamAsString.DataString = PropStreamAsString.DataString);
|
|
|
|
|
Result := Result and (lOther.PropStreamAsBASE64.DataString = PropStreamAsBASE64.DataString);
|
2017-02-10 14:19:55 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2020-12-12 19:26:18 +01:00
|
|
|
|
procedure TObjectWithCustomType.SetPropStreamAsBASE64(const Value: TStringStream);
|
2017-02-10 14:19:55 +01:00
|
|
|
|
begin
|
|
|
|
|
FPropStreamAsBASE64 := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
2020-12-12 19:26:18 +01:00
|
|
|
|
procedure TObjectWithCustomType.SetPropStreamAsString(const Value: TStringStream);
|
2017-02-10 14:19:55 +01:00
|
|
|
|
begin
|
|
|
|
|
FPropStreamAsString := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
2017-08-21 15:31:31 +02:00
|
|
|
|
procedure TObjectWithCustomType.SetPropStringArray(const Value: TArray<string>);
|
2017-02-10 14:19:55 +01:00
|
|
|
|
begin
|
|
|
|
|
FPropStringArray := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
2017-02-09 19:33:59 +01:00
|
|
|
|
procedure TObjectWithCustomType.SetPropStringList(const Value: TStringList);
|
|
|
|
|
begin
|
2020-05-04 12:39:54 +02:00
|
|
|
|
fPropStringList := Value;
|
2017-02-09 19:33:59 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2020-01-08 23:59:41 +01:00
|
|
|
|
{ TCustomerWithLF }
|
|
|
|
|
|
|
|
|
|
procedure TCustomerWithLF.ClearHistory;
|
|
|
|
|
begin
|
|
|
|
|
fHistory.Clear;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
constructor TCustomerWithLF.Create;
|
|
|
|
|
begin
|
|
|
|
|
inherited;
|
2020-03-31 16:23:22 +02:00
|
|
|
|
fHistory := TList<string>.Create;
|
2020-01-08 23:59:41 +01:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
destructor TCustomerWithLF.Destroy;
|
|
|
|
|
begin
|
|
|
|
|
fHistory.Free;
|
|
|
|
|
inherited;
|
|
|
|
|
end;
|
|
|
|
|
|
2020-03-31 16:23:22 +02:00
|
|
|
|
function TCustomerWithLF.GetHistory: string;
|
2020-01-08 23:59:41 +01:00
|
|
|
|
begin
|
2020-03-31 16:23:22 +02:00
|
|
|
|
Result := string.Join('|', fHistory.ToArray);
|
2020-01-08 23:59:41 +01:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TCustomerWithLF.MapDatasetToObject(const DataSet: TDataSet;
|
|
|
|
|
const Options: TMVCActiveRecordLoadOptions; var Handled: Boolean);
|
|
|
|
|
begin
|
|
|
|
|
inherited;
|
|
|
|
|
fHistory.Add('MapDatasetToObject');
|
|
|
|
|
end;
|
|
|
|
|
|
2020-12-12 19:26:18 +01:00
|
|
|
|
procedure TCustomerWithLF.MapObjectToParams(const Params: TFDParams; var Handled: Boolean);
|
2020-01-08 23:59:41 +01:00
|
|
|
|
begin
|
|
|
|
|
inherited;
|
|
|
|
|
fHistory.Add('MapObjectToParams');
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TCustomerWithLF.OnAfterDelete;
|
|
|
|
|
begin
|
|
|
|
|
inherited;
|
|
|
|
|
fHistory.Add('OnAfterDelete');
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TCustomerWithLF.OnAfterInsert;
|
|
|
|
|
begin
|
|
|
|
|
inherited;
|
|
|
|
|
fHistory.Add('OnAfterInsert');
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TCustomerWithLF.OnAfterInsertOrUpdate;
|
|
|
|
|
begin
|
|
|
|
|
inherited;
|
|
|
|
|
fHistory.Add('OnAfterInsertOrUpdate');
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TCustomerWithLF.OnAfterLoad;
|
|
|
|
|
begin
|
|
|
|
|
inherited;
|
|
|
|
|
fHistory.Add('OnAfterLoad');
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TCustomerWithLF.OnAfterUpdate;
|
|
|
|
|
begin
|
|
|
|
|
inherited;
|
|
|
|
|
fHistory.Add('OnAfterUpdate');
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TCustomerWithLF.OnBeforeDelete;
|
|
|
|
|
begin
|
|
|
|
|
inherited;
|
|
|
|
|
fHistory.Add('OnBeforeDelete');
|
|
|
|
|
end;
|
|
|
|
|
|
2020-03-31 16:23:22 +02:00
|
|
|
|
procedure TCustomerWithLF.OnBeforeExecuteSQL(var SQL: string);
|
2020-01-08 23:59:41 +01:00
|
|
|
|
begin
|
|
|
|
|
inherited;
|
|
|
|
|
fHistory.Add('OnBeforeExecuteSQL');
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TCustomerWithLF.OnBeforeInsert;
|
|
|
|
|
begin
|
|
|
|
|
inherited;
|
|
|
|
|
fHistory.Add('OnBeforeInsert');
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TCustomerWithLF.OnBeforeInsertOrUpdate;
|
|
|
|
|
begin
|
|
|
|
|
inherited;
|
|
|
|
|
fHistory.Add('OnBeforeInsertOrUpdate');
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TCustomerWithLF.OnBeforeLoad;
|
|
|
|
|
begin
|
|
|
|
|
inherited;
|
|
|
|
|
fHistory.Add('OnBeforeLoad');
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TCustomerWithLF.OnBeforeUpdate;
|
|
|
|
|
begin
|
|
|
|
|
inherited;
|
|
|
|
|
fHistory.Add('OnBeforeUpdate');
|
|
|
|
|
end;
|
|
|
|
|
|
2020-03-31 00:47:35 +02:00
|
|
|
|
procedure TCustomerWithLF.OnValidation(const Action: TMVCEntityAction);
|
2020-01-08 23:59:41 +01:00
|
|
|
|
begin
|
|
|
|
|
inherited;
|
|
|
|
|
fHistory.Add('OnValidation');
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
{ TNullablesTest }
|
|
|
|
|
|
|
|
|
|
destructor TNullablesTest.Destroy;
|
|
|
|
|
begin
|
|
|
|
|
ff_blob.Free;
|
|
|
|
|
inherited;
|
|
|
|
|
end;
|
|
|
|
|
|
2020-05-04 12:39:54 +02:00
|
|
|
|
{ TPartialSerializableType }
|
|
|
|
|
|
|
|
|
|
constructor TPartialSerializableType.Create;
|
|
|
|
|
begin
|
|
|
|
|
inherited;
|
|
|
|
|
fProp1 := 'prop1';
|
|
|
|
|
fProp2 := 'prop2';
|
|
|
|
|
fProp3 := 'prop3';
|
|
|
|
|
fProp4 := 'prop4';
|
|
|
|
|
end;
|
|
|
|
|
|
2020-09-21 12:42:38 +02:00
|
|
|
|
{ TListOfSomething }
|
|
|
|
|
|
|
|
|
|
constructor TListOfSomething.Create;
|
|
|
|
|
begin
|
|
|
|
|
inherited;
|
|
|
|
|
fListOfString := TList<string>.Create;
|
|
|
|
|
fListOfInteger := TList<Integer>.Create;
|
|
|
|
|
fListOfBoolean := TList<Boolean>.Create;
|
|
|
|
|
fListOfDouble := TList<Double>.Create;
|
|
|
|
|
// fListOfListOfString := TList < TList < string >>.Create;
|
|
|
|
|
fListOfString.Add('String1');
|
|
|
|
|
fListOfString.Add('String2');
|
|
|
|
|
fListOfInteger.Add(1001);
|
|
|
|
|
fListOfInteger.Add(2002);
|
|
|
|
|
fListOfBoolean.Add(true);
|
|
|
|
|
fListOfBoolean.Add(false);
|
|
|
|
|
|
|
|
|
|
fListOfDouble.Add(1234.5678);
|
|
|
|
|
fListOfDouble.Add(2345.6789);
|
|
|
|
|
|
|
|
|
|
// fListOfListOfString.Add(TList<string>.Create);
|
|
|
|
|
// fListOfListOfString.Last.Add('String1.1');
|
|
|
|
|
// fListOfListOfString.Last.Add('String1.2');
|
|
|
|
|
//
|
|
|
|
|
// fListOfListOfString.Add(TList<string>.Create);
|
|
|
|
|
// fListOfListOfString.Last.Add('String2.1');
|
|
|
|
|
// fListOfListOfString.Last.Add('String2.2');
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
destructor TListOfSomething.Destroy;
|
|
|
|
|
begin
|
|
|
|
|
fListOfString.Free;
|
|
|
|
|
fListOfInteger.Free;
|
|
|
|
|
fListOfBoolean.Free;
|
|
|
|
|
fListOfDouble.Free;
|
|
|
|
|
// fListOfListOfString.Free;
|
|
|
|
|
inherited;
|
|
|
|
|
end;
|
|
|
|
|
|
2020-11-04 19:06:54 +01:00
|
|
|
|
{ TMyObjectWithUTC }
|
|
|
|
|
|
|
|
|
|
function TMyObjectWithUTC.Equals(Obj: TObject): Boolean;
|
|
|
|
|
begin
|
2020-12-12 19:26:18 +01:00
|
|
|
|
Result := DateTimeToMilliseconds((Obj as TMyObjectWithUTC).MyDateTime)
|
|
|
|
|
= DateTimeToMilliseconds(Self.MyDateTime);
|
2020-11-04 19:06:54 +01:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMyObjectWithUTC.SetMyDateTime(const Value: TDateTime);
|
|
|
|
|
begin
|
|
|
|
|
FMyDateTime := Value;
|
|
|
|
|
end;
|
|
|
|
|
|
2021-09-23 22:52:28 +02:00
|
|
|
|
{ TCustomer }
|
|
|
|
|
|
|
|
|
|
procedure TCustomer.Assign(Customer: TCustomer);
|
|
|
|
|
begin
|
|
|
|
|
Self.fID := Customer.fID;
|
|
|
|
|
Self.fCode := Customer.fCode;
|
|
|
|
|
Self.fCompanyName := Customer.fCompanyName;
|
|
|
|
|
Self.fCity := Customer.fCity;
|
|
|
|
|
Self.fRating := Customer.fRating;
|
|
|
|
|
Self.fNote := Customer.fNote;
|
|
|
|
|
Self.fCreationTime := Customer.fCreationTime;
|
|
|
|
|
Self.fCreationDate := Customer.fCreationDate;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TCustomer.Clone: TCustomer;
|
|
|
|
|
begin
|
|
|
|
|
Result := TCustomer.Create;
|
|
|
|
|
Result.Assign(Self);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TCustomer.ToString: String;
|
|
|
|
|
begin
|
|
|
|
|
Result := inherited + Format(' [ID:%5d][Company: %s]', [ID.ValueOrDefault, CompanyName.ValueOrDefault]);
|
|
|
|
|
end;
|
|
|
|
|
|
2022-08-01 19:11:42 +02:00
|
|
|
|
|
|
|
|
|
initialization
|
|
|
|
|
|
|
|
|
|
ActiveRecordMappingRegistry.AddEntity('customers', TCustomer);
|
|
|
|
|
|
2015-12-22 12:29:25 +01:00
|
|
|
|
end.
|