unit fmMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    ListBox2: TListBox;
    ListBox3: TListBox;
    btnFirst: TButton;
    btnSecond: TButton;
    LabeledEdit1: TLabeledEdit;
    procedure btnFirstClick(Sender: TObject);
    procedure btnSecondClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses uclasses;

{$R *.dfm}

procedure TForm1.btnFirstClick(Sender: TObject);
var
  aPortfolio : TPortfolio;
  aASL : TStringList;
  aCSL : TStringList;
  aBSL : TStringList;
  FAuthor : TAuthor;
  FCategory : TCategory;
  FBook : TBook;
  iCount : Integer;
  iCount1 : Integer;
begin
  aPortfolio := TPortfolio.Create;
  try
    aASL := aPortfolio.GetAuthors;
    FAuthor := TAuthor(aASL.Objects[0]);
    aCSL := FAuthor.GetCategories;
    for iCount :=  0 to aCSL.Count - 1 do
    begin
      FCategory := TCategory(aCSL.Objects[iCount]);
      aBSL := FCategory.GetBooks;

      for iCount1 := 0 to aBSL.Count - 1 do
      begin
        FBook := TBook(aBSL.Objects[iCount1]);
        ListBox2.Items.Add(FBook.GetName);
        ListBox3.Items.Add(IntToStr(FBook.GetPrice));
      end;
    end;
  finally
    FreeAndNil(aPortfolio);
  end;
end;

procedure TForm1.btnSecondClick(Sender: TObject);
var
  aPortfolio : TPortfolio;
  rSL : TStringList;
  FBook : TBook;
  iCount : Integer;
begin
  aPortfolio := TPortfolio.Create;
  try
    rSL := aPortfolio.GetBooks(Self.LabeledEdit1.Text);
    if Assigned(rSL) then
    begin
      for iCount := 0 to rSL.Count - 1 do
      begin
        FBook := TBook(rSL.Objects[iCount]);
        ListBox2.Items.Add(FBook.GetName);
        ListBox3.Items.Add(IntToStr(FBook.GetPrice));
      end;
      FreeAndNil(rSL);
    end;
  finally
    FreeAndNil(aPortfolio);
  end;
end;

end.
