Search

'TCollection'에 해당되는 글 1건

  1. 2007.08.17 TCollection 사용하기

TCollection 사용하기

Programming/Delphi 2007.08.17 00:54 Posted by 파란크리스마스

type
  TDatabase = class (TCollectionItem)
  private
    FDatabaseName: String;
  published
    property DatabaseName: String read FDatabaseName write FDatabaseName;
  end;

  TDatabaseList = class (TCollection)
  private
    function GetItem(Index: Integer): TDatabase;
  public
    function Add: TDatabase;
    property Item[Index: Integer]: TDatabase read GetItem;
  end;
 
{ TDatabaseList }

function TDatabaseList.Add: TDatabase;
begin
  result := inherited Add as TDatabase;
end;

function TDatabaseList.GetItem(Index: Integer): TDatabase;
begin
  result := inherited Items[Index] as TDatabase;
end;

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
var
  DatabaseList : TDatabaseList;
  aDatabase : TDatabase;
  i : Integer;
begin
  DatabaseList := TDatabaseList.Create(TDatabase);

  aDatabase := DatabaseList.Add;  // create one hair
  aDatabase.DatabaseName := 'Oracle';

  aDatabase := DatabaseList.Add;  // create another hair
  aDatabase.DatabaseName := 'MsSQL';

  for i :=0 to DatabaseList.Count-1 do begin
    Memo1.Lines.Add(DatabaseList.Item[i].DatabaseName);
  end
end;

신고


 

티스토리 툴바