unit uObjects;

interface

uses
  SysUtils, Variants, Classes, Controls, StdCtrls, Forms;

type
  TLBAdapter = class;
  TRunner = procedure(anAdapter: TLBAdapter) of object;

  TLBManager = class(TObject)
  private
    FList : TList;
  public
    Constructor Create;
    Destructor Destroy; override;

    procedure AddAdapter(anAdapter : TLBAdapter);
    procedure ForEcah(mainForm : TFormClass; aRunner : TRunner); virtual;
  end;

  TLBAdapter = class(TObject)
  private
    FLB : TListBox;
  public
    Constructor Create(alb : TListBox);
    property alb : TListBox read FLB;
  end;

  TExternalRoutines = class(TObject)
  public
    procedure GenRandomData(anAdapter : TLBAdapter);
    procedure ClearData(anAdapter : TLBAdapter);
    procedure Move(anAdapter : TLBAdapter);
    procedure SetSameSize(anAdapter : TLBAdapter);
  end;

implementation

{ TLBManager }

procedure TLBManager.AddAdapter(anAdapter: TLBAdapter);
begin
  FList.Add(anAdapter);
end;

constructor TLBManager.Create;
begin
  FList := TList.Create;
end;

destructor TLBManager.Destroy;
var
  iCount : Integer;
begin
  for iCount := FList.Count - 1 downto 0 do
  begin
    TLBAdapter(FList.Items[iCount]).Free;
  end;
  FList.Clear;
  FreeAndNil(FList);
  inherited;
end;

procedure TLBManager.ForEcah(mainForm: TFormClass; aRunner: TRunner);
var
  iCount : Integer;
begin
  for iCount := 0 to FList.Count - 1 do
  begin
    aRunner(TLBAdapter(FList.Items[iCount]));
  end;
end;

{ TLBAdapter }

constructor TLBAdapter.Create(alb: TListBox);
begin
  FLB := alb;
end;

{ TExternalRoutines }

procedure TExternalRoutines.ClearData(anAdapter: TLBAdapter);
begin
  anAdapter.alb.Items.Clear;
end;

procedure TExternalRoutines.GenRandomData(anAdapter: TLBAdapter);
var
  iCount : Integer;
begin
  Randomize;
  for iCount := 0 to 10 do
  begin
    anAdapter.alb.Items.Add(DateTimeToStr(Now));
    Sleep(Random(500));
  end;
end;

procedure TExternalRoutines.Move(anAdapter: TLBAdapter);
begin
  anAdapter.alb.Top := anAdapter.alb.Top + 25;
end;

procedure TExternalRoutines.SetSameSize(anAdapter: TLBAdapter);
begin
  anAdapter.alb.Width := 150;
  anAdapter.alb.Height := 200;
end;

end.
