(************************************************************************
*    This File is Part of the AHM Triton Tools                          *
*    for Borland Delphi and C++ Builder.                                *
*************************************************************************
* Copyright © 1995-1999 Alexander H. Mehlhorn (AHM) and Tritontools.com *
* All Rights reserved.                                                  *
*                                                                       *
*    For more Information contact us at                                 *
*    E-Mail : support@tritontools.com                                   *
*    URL : http://www.tritontools.com                                   *
*                                                                       *
*    AHM is copyright by Alexander H. Mehlhorn                          *
*    All Parts of this Collection were developed,                       *
*    designed and implemented by AHM                                    *
*                                                                       *
*    Under no Circumstances may you distribute this file                *
*    in this or any other format. This File is supplied                 *
*    as Evaluation of Source only. No Delphi Components may be developed*
*    using extracts or subsets of this code without expressed permission*
*    by AHM.                                                            *
*                                                                       *
*************************************************************************)
unit AHMTListHolder;
interface
uses
  Windows, Classes,AHMSystemClass;
{$I AHM.INC}
type
  TAHMListHolder = class;
  TAHMStringLists = class;
  TAHMStrings = class(TCollectionItem)
  private
    FStrings : TStrings;
    FAHMListHolder : TAHMListHolder;
    FListName: String;
    procedure SeTStrings(Value : TStrings);
    procedure SetDuplicates(const Value: TDuplicates);
    procedure SetSorted(const Value: Boolean);
    function GetDuplicates: TDuplicates;
    function GetSorted: Boolean;
  protected
    function GetDisplayName: string; override;
  public
    constructor Create(Collection: TCollection); override;
    Destructor Destroy; override;
    procedure Assign(Source : TPersistent); override;
    property Owner : TAHMListHolder read FAHMListHolder;
  published
    Property ListName : String read FListName write FListName;
    Property Items : TStrings read FStrings Write SetStrings;
    Property Sorted : Boolean read GetSorted write SetSorted default false;
    Property Duplicates : TDuplicates read GetDuplicates write SetDuplicates default dupIgnore;
  end;
  TAHMStringlists = class(TCollection)
  private
    FAHMListHolder : TAHMListHolder;
    function GeTAHMStrings(Index: Integer): TAHMStrings;
    procedure SeTAHMStrings(Index: Integer; Value: TAHMStrings);
  protected
    function GetOwner : TPersistent; override;
  public
    constructor Create(AOwner: TAHMListHolder);
    function Add : TAHMStrings;
    property Items[Index: Integer]: TAHMStrings
             read GeTAHMStrings write SeTAHMStrings; default;
  end;
  TAHMListHolder = class(TAHMSystemsComponent)
  private
    FAHMStrings : TAHMStringlists;
    procedure SetAHMStrings(Value: TAHMStringlists);
  protected
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property Lists: TAHMStringlists read FAHMStrings write SetAHMStrings;
  end;


implementation

procedure TAHMStrings.Assign(Source: TPersistent);
begin
  if Source is TAHMStrings then
  begin
    Items.Text:=TAHMStrings(Source).Items.Text;
    ListName:=TAHMStrings(Source).ListName;
    Sorted:=TAHMStrings(Source).Sorted;
    Duplicates:=TAHMStrings(Source).Duplicates;
    exit;
  end;
  inherited;
end;

constructor TAHMStrings.Create(Collection: TCollection);
begin
  inherited Create(Collection);
  FAHMListHolder :=(((Collection as TAHMStringlists).GetOwner) as TAHMListHolder);
  FStrings:=TStringlist.Create;
  FListName:='StringList';
end;

destructor TAHMStrings.Destroy;
begin
  FStrings.Free;
  inherited Destroy;
end;

{$IFDEF AHMINPRISE3}
function TAHMStrings.GetDisplayName: string;
begin
  Result := FListName;
end;
{$ENDIF}

function TAHMStrings.GetDuplicates: TDuplicates;
begin
  result:=TStringList(FStrings).Duplicates;
end;

function TAHMStrings.GetSorted: Boolean;
begin
  result:=TStringList(FStrings).Sorted;
end;

procedure TAHMStrings.SetDuplicates(const Value: TDuplicates);
begin
  TStringList(FStrings).Duplicates:=Value;
end;

procedure TAHMStrings.SetSorted(const Value: Boolean);
begin
  TStringList(FStrings).Sorted:=Value;
end;

procedure TAHMStrings.SeTStrings(Value : TStrings);
begin
  FStrings.Assign(Value);
end;

function TAHMStringlists.GetOwner: TPersistent;
begin
  Result := FAHMListHolder;
end;

constructor TAHMStringlists.Create(AOwner: TAHMListHolder);
begin
  inherited Create(TAHMStrings);
  FAHMListHolder := AOwner;
end;

function TAHMStringlists.Add : TAHMStrings;
begin
  Result := TAHMStrings(inherited Add)
end;

function TAHMStringlists.GeTAHMStrings(Index: Integer): TAHMStrings;
begin
  Result := TAHMStrings(inherited GetItem(Index));
end;

procedure TAHMStringlists.SeTAHMStrings(Index: Integer; Value: TAHMStrings);
begin
  inherited SetItem(Index, Value);
end;

constructor TAHMListHolder.Create(AOwner: TComponent);
begin
  inherited create(AOwner);
  FAHMStrings:=TAHMStringlists.Create(self);
end;

destructor TAHMListHolder.Destroy;
begin
  FAHMStrings.Free;
  inherited Destroy;
end;

procedure TAHMListHolder.SetAHMStrings(Value: TAHMStringlists);
begin
  FAHMStrings.Assign(Value);
end;

end.
