🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.delphi.bazy-danych
Article #82770

Re: X-DBData Components 1.8 ze wsparciem dla RAD Studio 10.2 Tokyo!

#82770
From: Krzysztof Szyszka
Date: Tue, 28 Mar 2017 17:47
138 lines
5119 bytes
> Użytkownik "Roman Tyczka"  napisał ...
>
> On Sat, 25 Mar 2017 19:26:38 +0100, Krzysztof Szyszka wrote:
>
> >    Komponenty zawarte z tym pakiecie pozwalają korzystać z: array of TObject,
> >    TList of TObject, TObjectList, TStringList, TWideStringList, TCollection,
> >    TArray<T: class>, TList<T: class>, TObjectList<T: class> i klas potomnych.
> >    Korzystając z data providerów można również obsłużyć dowolne indeksowane
> >    właściwości takie jak Fields, Controls, Components, Pages, Buttons, Forms, itp.
>
> Czy są wspierane kolekcje interfejsów?

Już tu kiedyś odpowiadałem na podobne pytanie:
Pakiet X-DBData wspiera każdą strukturę danych, do której potrafisz napisać prostego data providera.

W Delphi nie ma takiej gotowej struktury, jak "kolekcja interfejsów", więc w pakiecie nie ma również
gotowego data providera, ale jeśli korzystasz ze Springa, to możesz go dopisać do każdej potrzebnej 
Ci
struktury danych zawartej w modułach Springa.

Poniżej załączam przykładowy moduł XDBList.Spring.pas do obsługi springowego TList<T>.
W analogiczny sposób można dopisać data providera do każdej innej springowej struktury danych.

unit XDBList.Spring;

interface

uses Classes, Spring.Collections.Lists, XDBList;

type
  TXDBListProvider<T: class> = class(TXDBCustomListProvider)
  public
    type
      TInstance = TList<T>;
  private
    function GetInstance: TInstance; inline;
  protected
    property Instance: TInstance read GetInstance;
    function GetDataClass: TClass; override;
    function GetItemClass: TClass; override;
    function GetItemCount: Integer; override;
    function GetItemValue(Index: Integer): TObject; override;
    function GetOwnsObjects: Boolean; override;
    function IsOwnsObjectsStored: Boolean; virtual;
    procedure InsertItem(Index: Integer); override;
    procedure DeleteItem(Index: Integer); override;
  published
    property ExactMatch;
    property OwnsObjects stored IsOwnsObjectsStored;
    property AddClassField;
    property AddIndexField;
    property AddRecNoField;
    property ClassFieldName;
    property ClassFieldSize;
    property IndexFieldName;
    property RecNoFieldName;
    property StringFieldSize;
  end;

implementation

uses SysUtils;

{ TXDBListProvider<T> }

function TXDBListProvider<T>.GetInstance: TInstance;
begin
  Result := TInstance(inherited Instance);
end;

{ protected }

function TXDBListProvider<T>.GetDataClass: TClass;
begin
  Result := TInstance;
end;

function TXDBListProvider<T>.GetItemClass: TClass;
begin
  Result := T;
end;

function TXDBListProvider<T>.GetItemCount: Integer;
begin
  Result := Instance.Count;
end;

function TXDBListProvider<T>.GetItemValue(Index: Integer): TObject;
begin
  Result := Instance[Index];
end;

function TXDBListProvider<T>.GetOwnsObjects: Boolean;
begin
  if Instance is TObjectList<T> then
    Result := TObjectList<T>(Instance).OwnsObjects
  else Result := inherited GetOwnsObjects;
end;

function TXDBListProvider<T>.IsOwnsObjectsStored: Boolean;
begin
  if Instance is TObjectList<T> then Result := False
  else Result := inherited GetOwnsObjects;
end;

procedure TXDBListProvider<T>.InsertItem(Index: Integer);
begin
  if OwnsObjects then
    if ItemClass.InheritsFrom(TComponent) then
      Instance.Insert(Index, TComponentClass(ItemClass).Create(nil))
    else Instance.Insert(Index, ItemClass.Create)
  else Abort;
end;

procedure TXDBListProvider<T>.DeleteItem(Index: Integer);
var
  Item: T;
begin
  if OwnsObjects and not (Instance is TObjectList<T>) then
  begin
    Item := Instance[Index];
    Instance.Delete(Index);
    Item.Free;
  end
  else Instance.Delete(Index);
end;

end.


-- 
pozdrowienia
Krzysztof Szyszka, X-Files Software
Developer of X-DBGrid Component
Embarcadero Technology Partner
http://www.x-files.pl/
Join to "Delphi X-DBGrid Component Community"
https://plus.google.com/#communities/100842098152269100547 
Technical Details
Message-ID: <obe7jq$q4s$1@node2.news.atman.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!.POSTED!not-for-mail
References: <ob6cpc$v4m$2@node2.news.atman.pl> <1ox852n5tqyvb$.dlg@tyczka.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!.POSTED!not-for-mail
From: "Krzysztof Szyszka" <nomail@gazeta.pl>
Newsgroups: pl.comp.lang.delphi,pl.comp.lang.delphi.bazy-danych
Subject: Re: X-DBData Components 1.8 ze wsparciem dla RAD Studio 10.2 Tokyo!
Date: Tue, 28 Mar 2017 19:47:32 +0200
Organization: ATMAN - ATM S.A.
Lines: 139
Message-ID: <obe7jq$q4s$1@node2.news.atman.pl>
References: <ob6cpc$v4m$2@node2.news.atman.pl> <1ox852n5tqyvb$.dlg@tyczka.com>
NNTP-Posting-Host: 85-222-28-64.dynamic.chello.pl
Mime-Version: 1.0
X-Trace: node2.news.atman.pl 1490723258 26780 85.222.28.64 (28 Mar 2017 17:47:38 GMT)
X-Complaints-To: usenet@atman.pl
NNTP-Posting-Date: Tue, 28 Mar 2017 17:47:38 +0000 (UTC)
In-Reply-To: <1ox852n5tqyvb$.dlg@tyczka.com>
X-Priority: 3
X-MSMail-Priority: Normal
Importance: Normal
X-Newsreader: Microsoft Windows Live Mail 16.4.3528.331
X-MimeOLE: Produced By Microsoft MimeOLE V16.4.3528.331
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit