Ignore:
Timestamp:
Sep 10, 2022, 6:26:39 PM (2 years ago)
Author:
chronos
Message:
  • Modified: Code cleanup.
  • Modified: Use Generics.Collections.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • PersistentData/UPDClient.pas

    r362 r561  
    11unit UPDClient;
    22
    3 {$mode delphi}
    4 
    53interface
    64
    75uses
    8   Classes, SysUtils, SpecializedList, SpecializedDictionary;
     6  Classes, SysUtils, Generics.Collections, UGenerics;
    97
    108const
     
    3331    destructor Destroy; override;
    3432    procedure Assign(Source: TObjectProxy);
     33  end;
     34
     35  { TObjectProxies }
     36
     37  TObjectProxies = class(TObjectList<TObjectProxy>)
     38    function AddProxy: TObjectProxy;
    3539  end;
    3640
     
    5963    ObjectName: string;
    6064    Path: string;
    61     Objects: TListObject; // TListObject<TObjectProxy>
     65    Objects: TObjectList<TObjectProxy>;
    6266    procedure Clear;
    6367    constructor Create;
     
    7478  end;
    7579
    76   { TPDTypePropertyList }
    77 
    78   TPDTypePropertyList = class(TListObject)
     80  { TPDTypeProperties }
     81
     82  TPDTypeProperties = class(TObjectList<TPDTypeProperty>)
    7983    Client: TPDClient;
    80     procedure AddSimple(Name: string; TypeName: string; Unique: Boolean = False;
    81       Index: Boolean = False);
     84    function AddSimple(Name: string; TypeName: string; Unique: Boolean = False;
     85      Index: Boolean = False): TPDTypeProperty;
    8286  end;
    8387
     
    9195    Name: string;
    9296    DbType: string;
    93     Properties: TPDTypePropertyList;
     97    Properties: TPDTypeProperties;
    9498    function IsDefined: Boolean;
    9599    procedure Define;
     
    100104  end;
    101105
    102   { TPDTypeList }
    103 
    104   TPDTypeList = class(TListObject)
     106  { TPDTypes }
     107
     108  TPDTypes = class(TObjectList<TPDType>)
    105109    Client: TPDClient;
    106110    function AddType(Name: string; DbType: string = ''): TPDType;
     
    121125    procedure SetConnectionString(AValue: string); virtual;
    122126  public
    123     Types: TPDTypeList;
     127    Types: TPDTypes;
    124128    Version: string;
    125129    BackendName: string;
     
    149153  TPDClientClass = class of TPDClient;
    150154
    151   resourcestring
    152     SClientNotSet = 'Client not set';
    153     SNotSupported = 'Not supported';
    154     SVersionMismatch = 'Version mismatch, client: %0:s, server: %1:s. Please upgrade database.';
    155     SCantLoadObjectWithoutId = 'Can''t load object without id';
     155resourcestring
     156  SClientNotSet = 'Client not set';
     157  SNotSupported = 'Not supported';
     158  SVersionMismatch = 'Version mismatch, client: %0:s, server: %1:s. Please upgrade database.';
     159  SCantLoadObjectWithoutId = 'Can''t load object without id';
    156160
    157161
    158162implementation
    159163
    160 { TPDTypePropertyList }
    161 
    162 procedure TPDTypePropertyList.AddSimple(Name: string; TypeName: string;
    163   Unique: Boolean; Index: Boolean);
    164 var
    165   NewProperty: TPDTypeProperty;
    166 begin
    167   NewProperty := TPDTypeProperty(AddNew(TPDTypeProperty.Create));
    168   NewProperty.Name := Name;
    169   NewProperty.DbType := Client.Types.SearchByName(TypeName);
    170   NewProperty.Unique := Unique;
    171   NewProperty.Index := Index;
    172 end;
    173 
    174 
    175 { TPDTypeList }
    176 
    177 function TPDTypeList.AddType(Name: string; DbType: string = ''): TPDType;
    178 begin
    179   Result := TPDType(AddNew(TPDType.Create));
     164{ TObjectProxies }
     165
     166function TObjectProxies.AddProxy: TObjectProxy;
     167begin
     168  Result := TObjectProxy.Create;
     169  Add(Result);
     170end;
     171
     172{ TPDTypeProperties }
     173
     174function TPDTypeProperties.AddSimple(Name: string; TypeName: string;
     175  Unique: Boolean = False; Index: Boolean = False): TPDTypeProperty;
     176begin
     177  Result := TPDTypeProperty.Create;
     178  Result.Name := Name;
     179  Result.DbType := Client.Types.SearchByName(TypeName);
     180  Result.Unique := Unique;
     181  Result.Index := Index;
     182  Add(Result);
     183end;
     184
     185{ TPDTypes }
     186
     187function TPDTypes.AddType(Name: string; DbType: string = ''): TPDType;
     188begin
     189  Result := TPDType.Create;
    180190  Result.Client := Client;
    181191  Result.Name := Name;
    182192  Result.DbType := DbType;
    183 end;
    184 
    185 function TPDTypeList.SearchByName(Name: string): TPDType;
     193  Add(Result);
     194end;
     195
     196function TPDTypes.SearchByName(Name: string): TPDType;
    186197var
    187198  I: Integer;
     
    220231constructor TPDType.Create;
    221232begin
    222   Properties := TPDTypePropertyList.Create;
     233  Properties := TPDTypeProperties.Create;
    223234end;
    224235
    225236destructor TPDType.Destroy;
    226237begin
    227   Properties.Free;
    228   inherited Destroy;
     238  FreeAndNil(Properties);
     239  inherited;
    229240end;
    230241
     
    256267destructor TObjectProxy.Destroy;
    257268begin
    258   Properties.Free;
    259   inherited Destroy;
     269  FreeAndNil(Properties);
     270  inherited;
    260271end;
    261272
     
    282293begin
    283294  ColumnsFilter := TListString.Create;
    284   Objects := TListObject.Create;
     295  Objects := TObjectList<TObjectProxy>.Create;
    285296end;
    286297
    287298destructor TListProxy.Destroy;
    288299begin
    289   Objects.Free;
    290   ColumnsFilter.Free;
    291   inherited Destroy;
     300  FreeAndNil(Objects);
     301  FreeAndNil(ColumnsFilter);
     302  inherited;
    292303end;
    293304
     
    313324procedure TPDClient.SetConnectionString(AValue: string);
    314325begin
    315 
    316326end;
    317327
     
    347357    NewObject.Load;
    348358
    349     DbVersion := NewObject.Properties.Values['Version'];
     359    DbVersion := NewObject.Properties.Items['Version'];
    350360    if Version <> DbVersion then
    351361      raise Exception.Create(Format(SVersionMismatch, [Version, DbVersion]));
     
    397407    Tables.Count := NewProxy.Objects.Count;
    398408    for I := 0 to NewProxy.Objects.Count - 1 do
    399       Tables[I] := TObjectProxy(NewProxy.Objects[I]).Properties.Values['TABLE_NAME'];
     409      Tables[I] := TObjectProxy(NewProxy.Objects[I]).Properties.Items['TABLE_NAME'];
    400410
    401411    for I := 0 to Types.Count - 1 do
     
    415425begin
    416426  inherited;
    417   Types := TPDTypeList.Create;
     427  Types := TPDTypes.Create;
    418428  Types.Client := Self;
    419429  InitSystemTypes;
     
    422432destructor TPDClient.Destroy;
    423433begin
    424   Types.Free;
    425   inherited Destroy;
     434  FreeAndNil(Types);
     435  inherited;
    426436end;
    427437
     
    436446procedure TPDClient.Install;
    437447begin
    438 
    439448end;
    440449
     
    446455procedure TPDClient.Update;
    447456begin
    448 
    449457end;
    450458
Note: See TracChangeset for help on using the changeset viewer.