fmmain.pas

来自「多数代码可以直接在Delphi6和Delphi7环境下运行。部分涉及.NET技术」· PAS 代码 · 共 93 行

PAS
93
字号
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.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?