Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


ID: 25928, The Composite

by Thomas Groschke Email: Anonymous


The composite pattern to group objects to be treated in the same way as a single instance of an object
Download Details
FTP  download also available
CDN Login Required to Download. (You will be redirected to the login page if you click on the Download Link)
To download this, you must have registered:
A free membership

For Delphi, Version 5.0  to 11.0 182 downloads
Copyright: No significant restrictions


Size: 842 bytes
Updated on Tue, 26 Aug 2008 11:13:35 GMT
Originally uploaded on Tue, 26 Aug 2008 10:22:55 GMT
SHA1 Hash: 348F53BA662D9AE38E41C534D721535E20BF14FF
MD5 Hash: D144CB81584625E98020B3D51C681D2E

    Explore the files in this upload

Description
The composite pattern to group objects to be treated in the same way as a single instance of an object.

Test it with thos code:
unit Main;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls,
Composite, Composite2, Iteratoren;

type
TForm1 = class(TForm)
TreeView1: TTreeView;
Button1: TButton;
TreeView2: TTreeView;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
Wurzel : TComponent;
procedure CreateWurzel;
procedure FillTree;
public
{ Public-Deklarationen }
end;

var
Form1: TForm1;

implementation


{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
FillTree;
end;

procedure TForm1.CreateWurzel;
var
E1_Komponente : TComponent;
E2_Komponente : TComponent;
E3_Komponente : TComponent;
E4_Komponente : TComponent;
begin
Wurzel := TComposite.Create('Wurzel', 'Die Wurzel');
E1_Komponente := TComposite.Create('E1', '#1 von Ebene 1');
E2_Komponente := TComposite.Create('E2', '#1 von Ebene 2');
E3_Komponente := TComposite.Create('E3', '#1 von Ebene 3');
Wurzel.Add(E1_Komponente);
E1_Komponente.Add(E2_Komponente);
E2_Komponente.Add(E3_Komponente);

E2_Komponente.Add(TLeaf.Create('B1','Blatt1 von E2'));
E2_Komponente.Add(TLeaf.Create('B2','Blatt2 von E2'));
E2_Komponente.Add(TLeaf.Create('B3','Blatt3 von E2'));

E3_Komponente.Add(TLeaf.Create('B1','Blatt1 von E3'));

E4_Komponente := TComposite.Create('E4', 'E4: Noch jemand da');
Wurzel.Add(E4_Komponente);
E4_Komponente.Add(TLeaf.Create('B1','Blatt1 von E4'));
end;


procedure TForm1.FillTree;

procedure Recur(iActNode: TTreeNode; iKomponente:TComponent);
var
ActNode: TTreeNode;
i : integer;
begin
if iKomponente <> nil then
for i := 0 to iKomponente.GetCount - 1 do
begin
ActNode := TreeView1.Items.AddChildObject(iActNode, iKomponente.GetChild(i).GetName, iKomponente.GetChild(i));
if iKomponente.GetChild(i).GetCount <> 0 then
Recur(ActNode,iKomponente.GetChild(i));
end;
end;


begin
TreeView1.Items.Clear;
Recur(nil, Wurzel);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
CreateWurzel;
end;

end.

   Latest Comments  View All Add New

Move mouse over comment to see the full text

Server Response from: ETNACDC03